private DestinationSessionParams createDestinationParams(MessageHandler messageHandler, String visitorName) { DestinationSessionParams destparams = new DestinationSessionParams(); destparams.setName(visitorName); destparams.setBroadcastName(false); destparams.setMessageHandler(messageHandler); return destparams; }
/** * This constructor is package private since only MessageBus is supposed to instantiate it. * * @param mbus The message bus that created this instance. * @param params The parameter object for this session. */ DestinationSession(MessageBus mbus, DestinationSessionParams params) { this.mbus = mbus; this.name = params.getName(); this.broadcastName = params.getBroadcastName(); this.msgHandler = params.getMessageHandler(); }
private RemoteServer(Slobrok slobrok, String slobrokId, Protocol protocol, String identity) { this.slobrok = slobrok; this.slobrokId = slobrok != null ? slobrok.configId() : slobrokId; mbus = new MessageBus(new RPCNetwork(new RPCNetworkParams() .setSlobrokConfigId(this.slobrokId) .setIdentity(new Identity(identity))), new MessageBusParams().addProtocol(protocol)); session = mbus.createDestinationSession(new DestinationSessionParams().setMessageHandler(queue)); }
public SharedDestinationSession(SharedMessageBus mbus, DestinationSessionParams params) { this.mbus = mbus; this.msgHandler.set(params.getMessageHandler()); this.session = mbus.messageBus().createDestinationSession(params.setMessageHandler(this)); this.mbusReference = mbus.refer(); }
private ServerTestDriver(RemoteClient client, boolean activateContainer, RequestHandler requestHandler, Protocol protocol, Module... guiceModules) { this.client = client; driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(guiceModules); if (activateContainer) { ContainerBuilder builder = driver.newContainerBuilder(); if (requestHandler != null) { builder.serverBindings().bind("mbus://*/*", requestHandler); } driver.activateContainer(builder); } MessageBusParams mbusParams = new MessageBusParams().addProtocol(protocol); RPCNetworkParams netParams = new RPCNetworkParams().setSlobrokConfigId(client.slobrokId()); SharedMessageBus mbus = SharedMessageBus.newInstance(mbusParams, netParams); ServerSession session = mbus.newDestinationSession(new DestinationSessionParams()); server = new MbusServer(driver, session); server.start(); session.release(); mbus.release(); }
/** * <p>Creates a destination session on top of this message bus using the * given handlers and parameter object.</p> * * @param params The parameters to control the session. * @return The created session. */ public synchronized DestinationSession createDestinationSession(DestinationSessionParams params) { if (destroyed.get()) { throw new IllegalStateException("Object is destroyed."); } if (sessions.containsKey(params.getName())) { throw new IllegalArgumentException("Name '" + params.getName() + "' is not unique."); } DestinationSession session = new DestinationSession(this, params); sessions.put(params.getName(), session); if (params.getBroadcastName()) { net.registerSession(params.getName()); } return session; }
/** * <p>This is a convenience method to call {@link * #createDestinationSession(DestinationSessionParams)} with default values * for the {@link DestinationSessionParams} object.</p> * * @param name The local unique name for the created session. * @param broadcastName Whether or not to broadcast this session's name on * the network. * @param handler The handler to receive the messages for the session. * @return The created session. */ public DestinationSession createDestinationSession(String name, boolean broadcastName, MessageHandler handler) { return createDestinationSession( new DestinationSessionParams() .setName(name) .setBroadcastName(broadcastName) .setMessageHandler(handler)); }