public void init(String props, String name, AddressGenerator generator, int bind_port) throws Throwable { channel=new JChannel(props).addAddressGenerator(generator).setName(name); if(bind_port > 0) { TP transport=channel.getProtocolStack().getTransport(); transport.setBindPort(bind_port); } disp=new RpcDispatcher(channel, this).setMembershipListener(this).setMethodLookup(id -> METHODS[id]) .setMarshaller(new UPerfMarshaller()); channel.connect(groupname); local_addr=channel.getAddress(); try { MBeanServer server=Util.getMBeanServer(); JmxConfigurator.registerChannel(channel, server, "jgroups", channel.getClusterName(), true); } catch(Throwable ex) { System.err.println("registering the channel in JMX failed: " + ex); } if(members.size() < 2) return; Address coord=members.get(0); Config config=disp.callRemoteMethod(coord, new MethodCall(GET_CONFIG), new RequestOptions(ResponseMode.GET_ALL, 5000)); if(config != null) { applyConfig(config); System.out.println("Fetched config from " + coord + ": " + config + "\n"); } else System.err.println("failed to fetch config from " + coord); }
protected <T> GroupRequest<T> cast(final Collection<Address> dests, Buffer data, RequestOptions options, boolean block_for_results) throws Exception { if(options == null) { log.warn("request options were null, using default of sync"); options=RequestOptions.SYNC(); if((tmp != null && tmp.getDiscardOwnMessages()) || options.transientFlagSet(Message.TransientFlag.DONT_LOOPBACK)) { if(local_addr == null) local_addr=tmp != null? tmp.getAddress() : null; real_dests.remove(local_addr); if(options.hasExclusionList()) Stream.of(options.exclusionList()).forEach(real_dests::remove); log.trace("destination list is empty, won't send message"); return empty_group_request; boolean sync=options.mode() != ResponseMode.GET_NONE; boolean non_blocking=!sync || !block_for_results, anycast=options.anycasting(); if(non_blocking) updateStats(real_dests, anycast, sync, 0);
/** * The timeout (in milliseconds) for blocking updates */ public long getTimeout() { return call_options.timeout(); }
protected void configChange(String name) throws Exception { int tmp=Util.readIntFromStdin(name + ": "); ConfigChange change=new ConfigChange(name, tmp); invokeRpc(configChange, RequestOptions.SYNC().flags(Message.Flag.RSVP), change); }
public T execute(Buffer data, boolean block_for_results) throws Exception { if(corr == null) return null; sendRequest(data); if(!block_for_results || options.mode() == ResponseMode.GET_NONE) return null; long timeout=options.timeout(); return timeout > 0? waitForCompletion(options.timeout(), TimeUnit.MILLISECONDS) : waitForCompletion(); }
public void start(String props, String name) throws Exception { this.props=props; this.name=name; StringBuilder sb=new StringBuilder(); sb.append("\n\n----------------------- MPerf -----------------------\n"); sb.append("Date: ").append(new Date()).append('\n'); sb.append("Run by: ").append(System.getProperty("user.name")).append("\n"); sb.append("JGroups version: ").append(Version.description).append('\n'); System.out.println(sb); channel=new JChannel(props); channel.setName(name); disp=new RpcDispatcher(channel, this).setMembershipListener(this).setMethodLookup(id -> METHODS[id]) .setMarshaller(new MperfMarshaller()); send_options.mode(sync? ResponseMode.GET_ALL : ResponseMode.GET_NONE); if(oob) send_options.flags(Message.Flag.OOB); channel.connect("mperf"); local_addr=channel.getAddress(); JmxConfigurator.registerChannel(channel, Util.getMBeanServer(), "jgroups", "mperf", true); // send a CONFIG_REQ to the current coordinator, so we can get the current config Address coord=channel.getView().getCoord(); if(coord != null && !local_addr.equals(coord)) invokeRpc(configReq, coord, RequestOptions.ASYNC().flags(Message.Flag.RSVP), local_addr); }
String line=Util.readStringFromStdin(": "); if(line.startsWith("help")) { System.out.println("unicast <text> // unicasts to all members of local view\n" + System.out.println("invoking method in " + dest + ": "); try { Object rsp=disp.callRemoteMethod(dest, call, new RequestOptions(ResponseMode.GET_ALL, RPC_TIMEOUT)); System.out.println("rsp from " + dest + ": " + rsp); SiteMaster dest=new SiteMaster(site_master); System.out.println("invoking method in " + dest + ": "); Object rsp=disp.callRemoteMethod(dest, call, new RequestOptions(ResponseMode.GET_ALL, RPC_TIMEOUT)); System.out.println("rsp from " + dest + ": " + rsp); new RequestOptions(ResponseMode.GET_ALL, RPC_TIMEOUT).anycasting(true)); for(Map.Entry<Address,Rsp<Object>> entry: rsps.entrySet()) { Address sender=entry.getKey(); Rsp<Object> rsp=entry.getValue(); if(rsp.wasUnreachable()) System.out.println("<< unreachable: " + sender); else System.out.println("<< " + rsp.getValue() + " from " + sender); new RequestOptions(ResponseMode.GET_ALL, RPC_TIMEOUT).anycasting(false)); rsps.entrySet().stream().forEach( entry -> { Rsp<Object> val=entry.getValue(); System.out.println("<< " + val.getValue() + " from " + entry.getKey()); });
RspList<Object> quotes=disp.callRemoteMethods(null, "getQuote", new Object[]{stock_name}, new Class[]{String.class}, new RequestOptions(ResponseMode.GET_ALL, 10000)); for(Rsp<Object> rsp : quotes.values()) { Object quote=rsp.getValue(); if(quote == null || quote instanceof Throwable) continue; disp.callRemoteMethods(null, "setQuote", new Object[]{stock_name, val}, new Class[]{String.class, Float.class}, new RequestOptions(ResponseMode.GET_FIRST, 0)); listbox.removeAll(); showMsg("Getting all stocks:"); RspList<Object> rsp_list=disp.callRemoteMethods(null, "getAllStocks", null, null, new RequestOptions(ResponseMode.GET_ALL, 5000)); for(Rsp rsp : rsp_list.values()) { Object obj=rsp.getValue(); if(obj == null || obj instanceof Throwable) continue;
V val=l1_cache.get(key); if(val != null) { if(log.isTraceEnabled()) log.trace("returned value " + val + " for " + key + " from L1 cache"); return val; RspList<Object> rsps=disp.callRemoteMethods(null, new MethodCall(GET, key), new RequestOptions(ResponseMode.GET_ALL, call_timeout)); for(Rsp rsp: rsps.values()) { Object obj=rsp.getValue(); if(obj == null || obj instanceof Throwable) continue; val=(Cache.Value<Value<V>>)rsp.getValue(); if(val != null) { tmp=val.getValue(); if(log.isWarnEnabled()) log.warn("get() failed", t); return null;
public void destroy() { if (disp != null) { try { MethodCall call = new MethodCall("removeNode", new Object[] {panel.my_addr}, new Class[] {Object.class}); disp.callRemoteMethods(null, call, new RequestOptions(ResponseMode.GET_ALL, 5000)); } catch (Exception e) { log.error(e.toString()); } channel.close(); disp = null; if (panel != null) { panel.stop(); panel = null; } } }
public void callRemote( boolean excludeSelf,String eventfqn,Event<?> event) throws Exception { // we need to copy the vector, otherwise the modification below will throw an exception because the underlying // vector is unmodifiable List<Address> v=new ArrayList<Address>(c.getView().getMembers()); if(excludeSelf) { v.remove(c.getAddress()); d.callRemoteMethods(v, "remoteEventChange", new Object[]{}, new Class[]{String.class,Event.class}, new RequestOptions(ResponseMode.GET_NONE, 0)); } else { d.callRemoteMethods(null, "remoteEventChange", new Object[]{}, new Class[]{String.class,Event.class}, new RequestOptions(ResponseMode.GET_NONE, 0)); } }
private void mcastPut(K key, V val, short repl_count, long caching_time, boolean synchronous) { try { ResponseMode mode=synchronous? ResponseMode.GET_ALL : ResponseMode.GET_NONE; disp.callRemoteMethods(null, new MethodCall(PUT, key, val, repl_count, caching_time), new RequestOptions(mode, call_timeout)); } catch(Throwable t) { if(log.isWarnEnabled()) log.warn("put() failed", t); } }
private void move(Address dest, K key, V val, short repl_count, long caching_time, boolean synchronous) { try { ResponseMode mode=synchronous? ResponseMode.GET_ALL : ResponseMode.GET_NONE; disp.callRemoteMethod(dest, new MethodCall(PUT_FORCE, key, val, repl_count, caching_time, true), new RequestOptions(mode, call_timeout)); } catch(Throwable t) { if(log.isWarnEnabled()) log.warn("move() failed", t); } }
V val=l1_cache.get(key); if(val != null) { if(log.isTraceEnabled()) log.trace("returned value " + val + " for " + key + " from L1 cache"); return val; val=disp.callRemoteMethod(dest_node, new MethodCall(GET, key), new RequestOptions(ResponseMode.GET_FIRST, call_timeout)); if(log.isWarnEnabled()) log.warn("_get() failed", t); return null;
c=Util.keyPress(String.format(INPUT, num_msgs, Util.printBytes(msg_size), num_threads, num_senders <= 0? "all" : String.valueOf(num_senders), sync, oob)); initiator=true; results.reset(getSenders()); invokeRpc(clearResults,RequestOptions.SYNC().flags(Message.Flag.RSVP)); invokeRpc(startSending, RequestOptions.ASYNC(), local_addr); break; case '2': System.out.println("view: " + channel.getView() + " (local address=" + channel.getAddress() + ")"); break; case '3': case 's': ConfigChange change=new ConfigChange("sync", !sync); invokeRpc(configChange, RequestOptions.SYNC().flags(Message.Flag.RSVP), change); break; case 'o': change=new ConfigChange("oob", !oob); invokeRpc(configChange, RequestOptions.SYNC().flags(Message.Flag.RSVP), change); break; case 'x': break; case 'X': invokeRpc(exit,RequestOptions.ASYNC()); break;
public Response sendSynchronous(String runtimeName, ResponseCommand command, long timeout) throws MessageException { try { byte[] payload = helper.serialize(command); View view = domainChannel.getView(); if (view == null) { throw new MessageException("Federation channel closed or not connected when sending message to: " + runtimeName); } Address address = helper.getRuntimeAddress(runtimeName, view); Message message = new Message(address, domainChannel.getAddress(), payload); RequestOptions options = new RequestOptions(ResponseMode.GET_ALL, timeout); Object o = dispatcher.sendMessage(message, options); assert o instanceof byte[] : "Expected byte[] but was " + o; return (Response) helper.deserialize((byte[]) o); } catch (Exception e) { throw new MessageException("Error sending message to runtime: " + runtimeName, e); } }
public ChannelCommandDispatcher(MessageDispatcher dispatcher, CommandMarshaller<C> marshaller, Group<Address> group, Duration timeout, CommandDispatcher<C> localDispatcher, Runnable closeTask) { this.dispatcher = dispatcher; this.marshaller = marshaller; this.group = group; this.timeout = timeout; this.localDispatcher = localDispatcher; this.closeTask = closeTask; this.localAddress = dispatcher.getChannel().getAddress(); this.options = new RequestOptions(ResponseMode.GET_ALL, this.timeout.toMillis(), false, FILTER, Message.Flag.DONT_BUNDLE, Message.Flag.OOB); }
log.warn("transport is not available !"); return; Header hdr=opts.hasExclusionList()? new MultiDestinationHeader(Header.REQ, 0, this.corr_id, opts.exclusionList()) : new Header(Header.REQ, 0, this.corr_id); .setFlag(opts.flags()).setTransientFlag(opts.transientFlags()); req.requestId(req_id); if(log.isTraceEnabled()) log.trace("%s: invoking multicast RPC [req-id=%d]", local_addr, req_id); requests.putIfAbsent(req_id, req); if(opts != null && opts.anycasting()) rpc_stats.addAnycast(false, 0, dest_mbrs); else if(opts.anycasting()) { if(opts.useAnycastAddresses()) { transport.down(msg.dest(new AnycastAddress(dest_mbrs)));
@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; }
protected void invokeRpcs() throws Exception { Average avg=new Average(); long min=Long.MAX_VALUE, max=0; RequestOptions opts=new RequestOptions(ResponseMode.GET_FIRST, 0).transientFlags(Message.TransientFlag.DONT_LOOPBACK); MethodCall call=new MethodCall((short)0); int print=num/10; opts.flags(Message.Flag.OOB); if(dont_bundle) opts.flags(Message.Flag.DONT_BUNDLE); if(channel.getView().size() != 2) { System.err.printf("Cluster must have exactly 2 members: %s\n", channel.getView()); return; for(int i=0; i < num; i++) { long start=System.nanoTime(); RspList<Void> rsps=disp.callRemoteMethods(null, call, opts); long time_ns=System.nanoTime() - start; if(i > 0 && i % print == 0) System.out.print("."); boolean all_received=rsps.values().stream().allMatch(Rsp::wasReceived); if(!all_received) System.err.printf("didn't receive all responses: %s\n", rsps);