@Override public <T> void remoteExecute(MethodCall action, long timeout, Handler<AsyncResult<T>> handler) { logTrace(() -> String.format("RemoteExecute action %s, handler %s", action, handler)); RequestOptions options = new RequestOptions() .setFlags(JGROUPS_FLAGS) .setMode(ResponseMode.GET_ALL) .setTimeout(timeout); try { NotifyingFuture<RspList<T>> notifyingFuture = this.<T>execute(action, options); notifyingFuture.setListener((future) -> vertx.executeBlocking((f) -> { try { RspList<T> rspList = future.get(); f.complete(futureDone(rspList)); } catch (Exception e) { f.fail(e); } }, handler)); } catch (Exception e) { handler.handle(Future.failedFuture(e)); } }
@Override public <T> T remoteExecute(MethodCall action, long timeout) { logTrace(() -> String.format("RemoteExecute sync action %s with timeout %s", action, timeout)); RequestOptions options = new RequestOptions() .setFlags(JGROUPS_FLAGS) .setMode(ResponseMode.GET_ALL) .setTimeout(timeout); try { NotifyingFuture<RspList<T>> notifyingFuture = this.<T>execute(action, options); RspList<T> rspList = notifyingFuture.get(timeout, TimeUnit.MILLISECONDS); return futureDone(rspList); } catch (Exception e) { throw new VertxException(e); } }
@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 ); }