/** * 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); }
@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 ); } } }
void sendMessages(int num) throws Exception { long start, stop; int show=num/10; if(show <=0) show=1; start=System.currentTimeMillis(); RequestOptions opts=new RequestOptions(ResponseMode.GET_ALL, TIMEOUT).flags(Message.Flag.DONT_BUNDLE, Message.Flag.NO_FC); byte[] data="bla".getBytes(); Buffer buf=new Buffer(data, 0, data.length); System.out.println("-- sending " + num + " messages"); for(int i=1; i <= num; i++) { disp.castMessage(null, buf, opts); if(i % show == 0) System.out.println("-- sent " + i); } stop=System.currentTimeMillis(); printStats(stop-start, num); }
/** * Invokes a method in all members and expects responses from members contained in dests (or all members if dests is null). * @param dests A list of addresses. If null, we'll wait for responses from all cluster members * @param method_call The method (plus args) to be invoked * @param opts A collection of call options, e.g. sync versus async, timeout etc * @return RspList A list of return values and flags (suspected, not received) per member, or null if the RPC is * asynchronous * @throws Exception If the sending of the message threw an exception. Note that <em>no</em> exception will be * thrown if any of the target members threw an exception, but this exception will be in the Rsp * object for the particular member in the RspList * @since 2.9 */ public <T> RspList<T> callRemoteMethods(Collection<Address> dests, MethodCall method_call, RequestOptions opts) throws Exception { if(dests != null && dests.isEmpty()) { // don't send if dest list is empty log.trace("destination list of %s() is empty: no need to send message", method_call.methodName()); return empty_rsplist; } Buffer buf=methodCallToBuffer(method_call, marshaller); RspList<T> retval=super.castMessage(dests, buf, opts); if(log.isTraceEnabled()) log.trace("dests=%s, method_call=%s, options=%s, responses: %s", dests, method_call, opts, retval); return retval; }
public RspList castMessage(final Vector dests, Message msg, int mode, long timeout) { return castMessage(dests, msg, mode, timeout, false); }
/** * {@inheritDoc} */ protected RspList<Object> castMessage(List<Address> dests, Message msg, boolean synchronous, long timeout) throws Exception { return dispatcher.castMessage(dests, msg, new RequestOptions(synchronous ? ResponseMode.GET_ALL : ResponseMode.GET_NONE, timeout)); }
/** * 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); }
void sendMessages(int num) throws Exception { long start, stop; int show=num/10; if(show <=0) show=1; start=System.currentTimeMillis(); RequestOptions opts=new RequestOptions(ResponseMode.GET_ALL, TIMEOUT).flags(Message.Flag.DONT_BUNDLE, Message.Flag.NO_FC); byte[] data="bla".getBytes(); Buffer buf=new Buffer(data, 0, data.length); System.out.println("-- sending " + num + " messages"); for(int i=1; i <= num; i++) { disp.castMessage(null, buf, opts); if(i % show == 0) System.out.println("-- sent " + i); } stop=System.currentTimeMillis(); printStats(stop-start, num); }
public RspList callRemoteMethods(Vector dests, MethodCall method_call, int mode, long timeout, boolean use_anycasting, boolean oob) { if(dests != null && dests.isEmpty()) { // don't send if dest list is empty if(log.isTraceEnabled()) log.trace(new StringBuffer("destination list of ").append(method_call.getName()). append("() is empty: no need to send message")); return new RspList(); } if(log.isTraceEnabled()) log.trace(new StringBuffer("dests=").append(dests).append(", method_call=").append(method_call). append(", mode=").append(mode).append(", timeout=").append(timeout)); byte[] buf; try { buf=req_marshaller != null? req_marshaller.objectToByteBuffer(method_call) : Util.objectToByteBuffer(method_call); } catch(Exception e) { // if(log.isErrorEnabled()) log.error("exception", e); // we will change this in 2.4 to add the exception to the signature // (see http://jira.jboss.com/jira/browse/JGRP-193). The reason for a RTE is that we cannot change the // signature in 2.3, otherwise 2.3 would be *not* API compatible to prev releases throw new RuntimeException("failure to marshal argument(s)", e); } Message msg=new Message(null, null, buf); if(oob) msg.setFlag(Message.OOB); RspList retval=super.castMessage(dests, msg, mode, timeout, use_anycasting); if(log.isTraceEnabled()) log.trace("responses: " + retval); return retval; }
Map<Address, Rsp<R>> responses = this.dispatcher.castMessage(null, message, options);
/** * Invokes a method in all members and expects responses from members contained in dests (or all members if dests is null). * @param dests A list of addresses. If null, we'll wait for responses from all cluster members * @param method_call The method (plus args) to be invoked * @param opts A collection of call options, e.g. sync versus async, timeout etc * @return RspList A list of return values and flags (suspected, not received) per member, or null if the RPC is * asynchronous * @throws Exception If the sending of the message threw an exception. Note that <em>no</em> exception will be * thrown if any of the target members threw an exception, but this exception will be in the Rsp * object for the particular member in the RspList * @since 2.9 */ public <T> RspList<T> callRemoteMethods(Collection<Address> dests, MethodCall method_call, RequestOptions opts) throws Exception { if(dests != null && dests.isEmpty()) { // don't send if dest list is empty log.trace("destination list of %s() is empty: no need to send message", method_call.methodName()); return empty_rsplist; } Buffer buf=methodCallToBuffer(method_call, marshaller); RspList<T> retval=super.castMessage(dests, buf, opts); if(log.isTraceEnabled()) log.trace("dests=%s, method_call=%s, options=%s, responses: %s", dests, method_call, opts, retval); return retval; }
@SuppressWarnings({"unchecked"}) public List<Response> sendSynchronous(ResponseCommand command, long timeout) throws MessageException { List<Response> values = new ArrayList<Response>(); List<Address> addresses = helper.getRuntimeAddressesInZone(zoneName, domainChannel.getView()); Vector<Address> dest = new Vector<Address>(addresses); byte[] payload = helper.serialize(command); Message message = new Message(null, domainChannel.getAddress(), payload); RequestOptions options = new RequestOptions(ResponseMode.GET_ALL, timeout); RspList responses; try { responses = domainDispatcher.castMessage(dest, message, options); } catch (Exception e) { throw new MessageException("Error sending message", e); } Set<Map.Entry<Address, Rsp<?>>> set = responses.entrySet(); for (Map.Entry<Address, Rsp<?>> entry : set) { Object val = entry.getValue().getValue(); assert val instanceof byte[] : " expected byte[] for response"; Response response = (Response) helper.deserialize((byte[]) val); values.add(response); } return values; }
Message operationMessage = new Message(null, getJGroupsLocalAddress(), (Serializable) operationParams); broadcastDispatcher.castMessage(destinations, operationMessage, GroupRequest.GET_NONE, 0);
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 ); }