@SuppressWarnings("resource") public ChannelCommandDispatcherFactory(ChannelCommandDispatcherFactoryConfiguration config) { this.marshallingContext = config.getMarshallingContext(); this.timeout = config.getTimeout(); JChannel channel = config.getChannel(); RequestCorrelator correlator = new RequestCorrelator(channel.getProtocolStack(), this, channel.getAddress()).setMarshaller(new CommandResponseMarshaller(config)); this.dispatcher = new MessageDispatcher() .setChannel(channel) .setRequestHandler(this) .setMembershipListener(this) .asyncDispatching(true) // Setting the request correlator starts the dispatcher .correlator(correlator) ; this.view.compareAndSet(null, channel.getView()); }
/** * Sends a message to all members and expects responses from members in dests (if non-null). * @param dests A list of group members from which to expect responses (if the call is blocking). * @param data The buffer * @param offset the offset into data * @param length the number of bytes to send * @param opts A set of options that govern the call. See {@link org.jgroups.blocks.RequestOptions} for details * @return RspList A list of Rsp elements, or null if the RPC is asynchronous * @throws Exception If the request cannot be sent * @since 4.0 */ public <T> RspList<T> castMessage(Collection<Address> dests, byte[] data, int offset, int length, RequestOptions opts) throws Exception { return castMessage(dests, new Buffer(data, offset, length), opts); }
public void start() throws Exception { channel=new JChannel(props); disp=new MessageDispatcher(channel, this).setMembershipListener(this); channel.connect("MessageDispatcherSpeedTestGroup"); try { if(server) { System.out.println("-- Started as server. Press ctrl-c to kill"); while(true) { Util.sleep(10000); } } else { sendMessages(num); } } catch(Throwable t) { t.printStackTrace(System.err); } finally { channel.close(); disp.stop(); } }
@Override public void run() { this.executorService.shutdownNow(); try { this.executorService.awaitTermination(this.timeout.toMillis(), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } this.dispatcher.stop(); this.dispatcher.getChannel().setUpHandler(null); // Cleanup any stray listeners for (ExecutorService executor : this.listeners.values()) { PrivilegedAction<List<Runnable>> action = () -> executor.shutdownNow(); WildFlySecurityManager.doUnchecked(action); } this.listeners.clear(); }
public MessageDispatcher(JChannel channel) { this.channel=channel; prot_adapter=new ProtocolAdapter(); if(channel != null) { channel.addChannelListener(this); local_addr=channel.getAddress(); installUpHandler(prot_adapter, true); } start(); }
public MessageDispatcher(PullPushAdapter adapter, Serializable id, MessageListener l, MembershipListener l2, RequestHandler req_handler) { this.adapter=adapter; this.id=id; setMembers(((Channel) adapter.getTransport()).getView().getMembers()); setRequestHandler(req_handler); setMessageListener(l); setMembershipListener(l2); handler=new PullPushHandler(); transport_adapter=new TransportAdapter(); adapter.addMembershipListener(handler); if(id == null) { // no other building block around, let's become the main consumer of this PullPushAdapter adapter.setListener(handler); } else { adapter.registerListener(id, handler); } Transport tp; if((tp=adapter.getTransport()) instanceof Channel) { local_addr=((Channel) tp).getLocalAddress(); // fixed bug #800774 } start(); }
public RspCommandResponse(Rsp<R> response) { this.response = response; }
@Override public void send(final Buffer data, final boolean synchronous, final long timeout) throws Exception { final RequestOptions options = synchronous ? RequestOptions.SYNC() : RequestOptions.ASYNC(); options.exclusionList( dispatcher.getChannel().getAddress() ); options.setTransientFlags( TransientFlag.DONT_LOOPBACK ); options.setTimeout( timeout ); if ( synchronous ) { try { RspList<Object> rspList = dispatcher.castMessage( null, data, options ); handleResponseProblems( rspList, null ); } catch (Exception e) { throw log.unableToSendWorkViaJGroups( e ); } } else { try { dispatcher.castMessageWithFuture( null, data, options ); } catch (RuntimeException e) { throw log.unableToSendWorkViaJGroups( e ); } } }
private void sendMessage(List<LuceneWork> queue) throws Exception { final String indexManagerName = getIndexName(); ServiceManager serviceManager = getExtendedSearchIntegrator().getServiceManager(); //send message to all listeners byte[] data = serviceManager.requestService( LuceneWorkSerializer.class ).toSerializedModel( queue ); data = MessageSerializationHelper.prependString( indexManagerName, data ); final MessageDispatcher dispatcher = new MessageDispatcher( channel ); final RequestOptions options = RequestOptions.SYNC() .exclusionList( channel.address() ) .setTransientFlags( TransientFlag.DONT_LOOPBACK ) .setTimeout( TIMEOUT ); //milliseconds Buffer buffer = new Buffer( data ); dispatcher.castMessage( null, buffer, options ); serviceManager.releaseService( LuceneWorkSerializer.class ); }
public MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2) { this.channel=channel; prot_adapter=new ProtocolAdapter(); if(channel != null) { local_addr=channel.getLocalAddress(); } setMessageListener(l); setMembershipListener(l2); if(channel != null) { channel.setUpHandler(prot_adapter); } start(); }
@Override public void start(Properties props, BuildContext context) { log.jGroupsStartingChannelProvider(); serviceManager = context.getServiceManager(); channelContainer = buildChannel( props ); checkForOldProperties( props ); NodeSelectorService masterNodeSelector = serviceManager.requestService( NodeSelectorService.class ); LuceneWorkSerializer luceneWorkSerializer = serviceManager.requestService( LuceneWorkSerializer.class ); JGroupsMasterMessageListener listener = new JGroupsMasterMessageListener( context, masterNodeSelector, luceneWorkSerializer ); JChannel channel = channelContainer.getChannel(); MessageListenerToRequestHandlerAdapter requestHandler = new MessageListenerToRequestHandlerAdapter( listener ); dispatcher = new MessageDispatcher( channel, requestHandler ); dispatcher.setMembershipListener( listener ); //Only now that the Dispatcher is installed we can start the channel: channelContainer.start(); masterNodeSelector.setLocalAddress( channel.getAddress() ); if ( !channel.flushSupported() ) { log.jGroupsFlushNotPresentInStack(); } if ( log.isDebugEnabled() ) { log.jgroupsFullConfiguration( channel.getProtocolStack().printProtocolSpecAsXML() ); } }
public void channelDisconnected(JChannel channel) { stop(); }
@Override public String getName() { return this.dispatcher.getChannel().getClusterName(); }
/** * Sends a unicast message and - depending on the options - returns a result * @param dest the target to which to send the unicast message. Must not be null. * @param data the payload to send * @param offset the offset at which the data starts * @param length the number of bytes to send * @param opts the options to be used * @return T the result. Null if the call is asynchronous (non-blocking) or if the response is null * @throws Exception If there was problem sending the request, processing it at the receiver, or processing * it at the sender. * @throws TimeoutException If the call didn't succeed within the timeout defined in options (if set) */ public <T> T sendMessage(Address dest, byte[] data, int offset, int length, RequestOptions opts) throws Exception { return sendMessage(dest, new Buffer(data, offset, length), opts); }
public MessageDispatcher(JChannel channel, RequestHandler req_handler) { this(channel); setRequestHandler(req_handler); }
public RpcDispatcher setMembershipListener(MembershipListener l) {return (RpcDispatcher)super.setMembershipListener(l);} public MethodLookup getMethodLookup() {return method_lookup;}
public <X extends MessageDispatcher> X setAsynDispatching(boolean flag) {return asyncDispatching(flag);} public <X extends MessageDispatcher> X asyncDispatching(boolean flag) {
public <X extends MessageDispatcher> X setCorrelator(RequestCorrelator c) {return correlator(c);} public <X extends MessageDispatcher> X correlator(RequestCorrelator c) {
public void onEvent(JoinDomain event) { try { domainChannel.connect(domainName); dispatcher.start(); } catch (Exception e) { monitor.error("Error joining the domain", e); } } }