net.engio.mbassy.bus.MBassador Java Examples

The following examples show how to use net.engio.mbassy.bus.MBassador. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Pong.java    From Entitas-Java with MIT License 6 votes vote down vote up
@Override
public void create() {
    AssetManager assetsManager = new AssetManager(new TestFileHandleResolver());
    BasePreferencesManager preferencesManager = new BasePreferencesManager();
    PongEngine engine = new PongEngine();
    engine.addManager(new BaseAssetsManager(assetsManager, preferencesManager));
    engine.addManager(new BasePhysicsManager(new Vector2(0,0)));
    engine.addManager(new BaseGUIManager(new BitmapFont(), null, engine));
    engine.addManager(new BaseSceneManager(engine));

    game = new PongGame(engine, new EGEventBus(new MBassador()));
    game.init();
    game.pushState(new PongState(engine));

}
 
Example #2
Source File: Examples.java    From Entitas-Java with MIT License 6 votes vote down vote up
@Override
public void create() {
    engine = new ExamplesEngine();
    entitas = new Entitas();

    preferencesManager.LOG_LEVEL = LogManager.LOG_DEBUG;
    AssetManager assetsManager = new AssetManager(new TestFileHandleResolver());
    engine.addManager(new AssetsManagerGDX(assetsManager, preferencesManager));
    engine.addManager(new PhysicsManagerGDX(new Vector2(0,-9.8f)));
    engine.addManager(new GUIManagerGDX(new ScreenViewport(),new BitmapFont(), engine));
    engine.addManager(new SceneManagerGDX(engine, entitas));
    engine.addManager(new LogManagerGDX(preferencesManager));
    engine.addManager(new InputManagerGDX(entitas, engine));
    engine.addManager(preferencesManager);

    game = new ExamplesGame(engine, new EventBusGDX(new MBassador()));
    game.init();
    game.pushState(new PlatformExampleState(engine, entitas));

}
 
Example #3
Source File: RollupService.java    From disthene with MIT License 6 votes vote down vote up
public RollupService(MBassador<DistheneEvent> bus, DistheneConfiguration distheneConfiguration, List<Rollup> rollups) {
    this.distheneConfiguration = distheneConfiguration;
    this.rollups = rollups;
    this.bus = bus;
    bus.subscribe(this);

    for(Rollup rollup : rollups) {
        if (maxRollup == null || maxRollup.getRollup() < rollup.getRollup()) {
            maxRollup = rollup;
        }
    }

    scheduler.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            flush();
        }
    }, 60 - ((System.currentTimeMillis() / 1000L) % 60), RATE, TimeUnit.SECONDS);
}
 
Example #4
Source File: StreamingContainerManager.java    From Bats with Apache License 2.0 5 votes vote down vote up
public StreamingContainerManager(LogicalPlan dag, boolean enableEventRecording, Clock clock)
{
  this.clock = clock;
  this.vars = new FinalVars(dag, clock.getTime());
  poolExecutor = Executors.newFixedThreadPool(4);
  // setup prior to plan creation for event recording
  if (enableEventRecording) {
    this.eventBus = new MBassador<>(BusConfiguration.Default(1, 1, 1));
  }
  this.plan = new PhysicalPlan(dag, this);
  this.journal = new Journal(this);
  init(enableEventRecording);
}
 
Example #5
Source File: ClientModel.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link ClientModel} backed by the specified
 * {@link ClientManager}.
 */
public ClientModel(ClientManager clientManager) {
    this.clientManager = Objects.requireNonNull(clientManager, "clientManager");
    this.bus = new MBassador<Object>(new BusConfiguration()
            .addFeature(Feature.SyncPubSub.Default())
            .addFeature(Feature.AsynchronousHandlerInvocation.Default())
            .addFeature(Feature.AsynchronousMessageDispatch.Default()));
}
 
Example #6
Source File: TaskModel.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link TaskModel} backed by the specified
 * {@link TaskManager}.
 */
public TaskModel(TaskManager taskManager) {
    this.taskManager = Objects.requireNonNull(taskManager, "taskManager");
    this.bus = new MBassador<Object>(new BusConfiguration()
            .addFeature(Feature.SyncPubSub.Default())
            .addFeature(Feature.AsynchronousHandlerInvocation.Default())
            .addFeature(Feature.AsynchronousMessageDispatch.Default()));
}
 
Example #7
Source File: ServiceLocator.java    From light with Apache License 2.0 5 votes vote down vote up
public MBassador<Map<String, Object>> getEventBus(String topic) {
    MBassador<Map<String, Object>> eventBus = eventBusMap.get(topic);
    if(eventBus == null) {
        eventBus = new MBassador<Map<String, Object>>();
        eventBusMap.put(topic, eventBus);
    }
    return eventBus;
}
 
Example #8
Source File: AbstractRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void publishEvent(Map<String, Object> eventMap) throws Exception {
    // get class name
    //System.out.println(this.getClass().getPackage());
    //System.out.println(this.getClass().getName());
    // check if publisher is enabled.
    Map map = getRuleByRuleClass(this.getClass().getName());
    Object isPublisher = map.get("isPublisher");
    if(isPublisher != null && (boolean)isPublisher) {
        //System.out.println("isPublisher");
        MBassador<Map<String, Object>> eventBus = ServiceLocator.getInstance().getEventBus((String)eventMap.get("category"));
        eventBus.publish(eventMap);
    }
}
 
Example #9
Source File: WriterThread.java    From disthene with MIT License 5 votes vote down vote up
public WriterThread(String name, MBassador<DistheneEvent> bus, Session session, PreparedStatement statement, Queue<Metric> metrics, Executor executor) {
    super(name);
    this.bus = bus;
    this.session = session;
    this.statement = statement;
    this.metrics = metrics;
    this.executor = executor;
}
 
Example #10
Source File: StatsService.java    From disthene with MIT License 5 votes vote down vote up
public StatsService(MBassador<DistheneEvent> bus, StatsConfiguration statsConfiguration, Rollup rollup) {
    this.statsConfiguration = statsConfiguration;
    this.bus = bus;
    this.rollup = rollup;
    bus.subscribe(this);

    scheduler.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            flush();
        }
    }, 60 - ((System.currentTimeMillis() / 1000L) % 60), statsConfiguration.getInterval(), TimeUnit.SECONDS);

}
 
Example #11
Source File: IndexService.java    From disthene with MIT License 5 votes vote down vote up
public IndexService(IndexConfiguration indexConfiguration, MBassador<DistheneEvent> bus) {
    this.indexConfiguration = indexConfiguration;

    bus.subscribe(this);

    Settings settings = ImmutableSettings.settingsBuilder()
            .put("cluster.name", indexConfiguration.getName())
            .build();
    client = new TransportClient(settings);
    for (String node : indexConfiguration.getCluster()) {
        client.addTransportAddress(new InetSocketTransportAddress(node, indexConfiguration.getPort()));
    }

    indexThread = new IndexThread(
            "distheneIndexThread",
            client,
            metrics,
            indexConfiguration.getIndex(),
            indexConfiguration.getType(),
            indexConfiguration.getBulk().getActions(),
            indexConfiguration.getBulk().getInterval()
    );

    indexThread.start();

    if (indexConfiguration.isCache()) {
        scheduler.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                expireCache();
            }
        }, indexConfiguration.getExpire(), indexConfiguration.getExpire(), TimeUnit.SECONDS);
    }
}
 
Example #12
Source File: AggregateService.java    From disthene with MIT License 5 votes vote down vote up
public AggregateService(MBassador<DistheneEvent> bus, DistheneConfiguration distheneConfiguration) {
    this.distheneConfiguration = distheneConfiguration;
    this.baseRollup = distheneConfiguration.getCarbon().getBaseRollup();
    this.bus = bus;
    bus.subscribe(this);

    scheduler.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            flush();
        }
    }, 60 - ((System.currentTimeMillis() / 1000L) % 60), RATE, TimeUnit.SECONDS);
}
 
Example #13
Source File: SumService.java    From disthene with MIT License 5 votes vote down vote up
public SumService(MBassador<DistheneEvent> bus, DistheneConfiguration distheneConfiguration, AggregationConfiguration aggregationConfiguration, BlacklistService blacklistService) {
    this.bus = bus;
    this.distheneConfiguration = distheneConfiguration;
    this.aggregationConfiguration = aggregationConfiguration;
    this.blacklistService = blacklistService;
    bus.subscribe(this);


    scheduler.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            flush();
        }
    }, 60 - ((System.currentTimeMillis() / 1000L) % 60), RATE, TimeUnit.SECONDS);
}
 
Example #14
Source File: StreamingContainerManager.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
private StreamingContainerManager(CheckpointState checkpointedState, boolean enableEventRecording)
{
  this.vars = checkpointedState.finals;
  this.clock = new SystemClock();
  poolExecutor = Executors.newFixedThreadPool(4);
  this.plan = checkpointedState.physicalPlan;
  this.eventBus = new MBassador<>(BusConfiguration.Default(1, 1, 1));
  this.journal = new Journal(this);
  init(enableEventRecording);
}
 
Example #15
Source File: StreamingContainerManager.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
public StreamingContainerManager(LogicalPlan dag, boolean enableEventRecording, Clock clock)
{
  this.clock = clock;
  this.vars = new FinalVars(dag, clock.getTime());
  poolExecutor = Executors.newFixedThreadPool(4);
  // setup prior to plan creation for event recording
  if (enableEventRecording) {
    this.eventBus = new MBassador<>(BusConfiguration.Default(1, 1, 1));
  }
  this.plan = new PhysicalPlan(dag, this);
  this.journal = new Journal(this);
  init(enableEventRecording);
}
 
Example #16
Source File: StreamingContainer.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
protected StreamingContainer(String containerId, StreamingContainerUmbilicalProtocol umbilical)
{
  this.jvmName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName();
  this.components = new HashSet<>();
  this.eventBus = new MBassador<>(BusConfiguration.Default(1, 1, 1));
  this.singletons = new HashMap<>();
  this.nodeRequests = new ArrayList<>();

  logger.debug("instantiated StramChild {}", containerId);
  this.umbilical = umbilical;
  this.containerId = containerId;
}
 
Example #17
Source File: StreamingContainerManager.java    From Bats with Apache License 2.0 5 votes vote down vote up
private StreamingContainerManager(CheckpointState checkpointedState, boolean enableEventRecording)
{
  this.vars = checkpointedState.finals;
  this.clock = new SystemClock();
  poolExecutor = Executors.newFixedThreadPool(4);
  this.plan = checkpointedState.physicalPlan;
  this.eventBus = new MBassador<>(BusConfiguration.Default(1, 1, 1));
  this.journal = new Journal(this);
  init(enableEventRecording);
}
 
Example #18
Source File: StreamingContainer.java    From Bats with Apache License 2.0 5 votes vote down vote up
protected StreamingContainer(String containerId, StreamingContainerUmbilicalProtocol umbilical)
{
  this.jvmName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName();
  this.components = new HashSet<>();
  this.eventBus = new MBassador<>(BusConfiguration.Default(1, 1, 1));
  this.singletons = new HashMap<>();
  this.nodeRequests = new ArrayList<>();

  logger.debug("instantiated StramChild {}", containerId);
  this.umbilical = umbilical;
  this.containerId = containerId;
}
 
Example #19
Source File: CarbonServer.java    From disthene with MIT License 4 votes vote down vote up
public CarbonServer(DistheneConfiguration configuration, MBassador<DistheneEvent> bus) {
    this.bus = bus;
    this.configuration = configuration;
}
 
Example #20
Source File: CarbonServerHandler.java    From disthene with MIT License 4 votes vote down vote up
public CarbonServerHandler(MBassador<DistheneEvent> bus, Rollup rollup) {
    this.bus = bus;
    this.rollup = rollup;
}
 
Example #21
Source File: MetricService.java    From disthene with MIT License 4 votes vote down vote up
public MetricService(MBassador<DistheneEvent> bus, BlacklistService blacklistService, DistheneConfiguration distheneConfiguration) {
    this.bus = bus;
    this.blacklistService = blacklistService;
    this.distheneConfiguration = distheneConfiguration;
    bus.subscribe(this);
}
 
Example #22
Source File: SingleWriterThread.java    From disthene with MIT License 4 votes vote down vote up
public SingleWriterThread(String name, MBassador<DistheneEvent> bus, Session session, PreparedStatement statement, Queue<Metric> metrics, Executor executor) {
    super(name, bus, session, statement, metrics, executor);
}
 
Example #23
Source File: BatchWriterThread.java    From disthene with MIT License 4 votes vote down vote up
BatchWriterThread(String name, MBassador<DistheneEvent> bus, Session session, PreparedStatement statement, Queue<Metric> metrics, Executor executor, int batchSize) {
    super(name, bus, session, statement, metrics, executor);
    this.batchSize = batchSize;
}
 
Example #24
Source File: MatchOne.java    From Entitas-Java with MIT License 4 votes vote down vote up
@Override
    public void create() {
        AssetManager assetsManager = new AssetManager(new TestFileHandleResolver());
        BasePreferencesManager preferencesManager = new BasePreferencesManager();
        MatchOneEngine engine = new MatchOneEngine();
        engine.addManager(new BaseAssetsManager(assetsManager, preferencesManager));
//        new Collections(new CollectionsFactory() {
//            @Override
//            public <T> List<T> createList(Class<T> clazz) {
//                if (clazz.equals(Integer.class))
//                    return (List<T>) new IntArrayList();
//                else
//                    return new ObjectArrayList();
//            }
//
//            @Override
//            public <T> Set createSet(Class<T> clazz) {
//                if (clazz.equals(Integer.class))
//                    return new IntArraySet();
//                else
//                    return new ObjectOpenHashSet();
//        }
//
//            @Override
//            public <K, V> Map createMap(Class<K> keyClazz, Class<V> valueClazz) {
//                return new Object2ObjectArrayMap();
//            }
//
//
//        });

        new EntitasCollections(new CollectionsFactories(){});

        MBassador bus = new MBassador(new IPublicationErrorHandler() {
            @Override
            public void handleError(PublicationError error) {
                Gdx.app.error("EBUS ERROR: ", error.toString());
            }
        });


        game = new MatchOneGame(engine, new EGEventBus(bus));
        game.init();
        game.pushState(new MatchOneState(engine));
    }
 
Example #25
Source File: EventBusGDX.java    From Entitas-Java with MIT License 4 votes vote down vote up
public EventBusGDX(MBassador ebus) {
    this.ebus = ebus;
}
 
Example #26
Source File: MBassadorConfigurationUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Before
public void prepareTests() {

    dispatcher = new MBassador<String>(this);
    dispatcher.subscribe(this);
}