Coverage Summary for Class: EventDispatchThread (org.ethereum.core)
Class |
Class, %
|
Method, %
|
Line, %
|
EventDispatchThread |
100%
(1/1)
|
75%
(3/4)
|
61.5%
(8/13)
|
1 /*
2 * This file is part of RskJ
3 * Copyright (C) 2017 RSK Labs Ltd.
4 * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>)
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package org.ethereum.core;
21
22 import co.rsk.panic.PanicProcessor;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 import java.util.concurrent.ExecutorService;
27 import java.util.concurrent.Executors;
28
29 /**
30 * The class intended to serve as an 'Event Bus' where all EthereumJ events are
31 * dispatched asynchronously from component to component or from components to
32 * the user event handlers.
33 *
34 * This made for decoupling different components which are intended to work
35 * asynchronously and to avoid complex synchronisation and deadlocks between them
36 *
37 * Created by Anton Nashatyrev on 29.12.2015.
38 */
39 public class EventDispatchThread {
40 private static final Logger logger = LoggerFactory.getLogger("blockchain");
41 private static final PanicProcessor panicProcessor = new PanicProcessor();
42
43 private static final ExecutorService executor = Executors.newSingleThreadExecutor();
44
45 private EventDispatchThread() {
46 // utility class can't be instantiated
47 }
48
49 public static void invokeLater(final Runnable r) {
50 executor.submit(() -> {
51 try {
52 r.run();
53 } catch (Exception e) {
54 logger.error("EDT task exception", e);
55 panicProcessor.panic("thread", String.format("EDT task exception %s", e.getMessage()));
56 }
57 });
58 }
59 }