/** * Sets the local member properties for broadcasting */ @Override public void setLocalMemberProperties(String listenHost, int listenPort, int securePort, int udpPort) { properties.setProperty("tcpListenHost",listenHost); properties.setProperty("tcpListenPort",String.valueOf(listenPort)); properties.setProperty("udpListenPort",String.valueOf(udpPort)); properties.setProperty("tcpSecurePort",String.valueOf(securePort)); try { if (localMember != null) { localMember.setHostname(listenHost); localMember.setPort(listenPort); } else { localMember = new MemberImpl(listenHost, listenPort, 0); localMember.setUniqueId(UUIDGenerator.randomUUID(true)); localMember.setPayload(getPayload()); localMember.setDomain(getDomain()); localMember.setLocal(true); } localMember.setSecurePort(securePort); localMember.setUdpPort(udpPort); localMember.getData(true, true); }catch ( IOException x ) { throw new IllegalArgumentException(x); } }
@SuppressWarnings("unused") public static void main(String[] args) throws Exception { if (args.length==0) usage(); main = Thread.currentThread(); ManagedChannel channel = (ManagedChannel) ChannelCreator.createChannel(args); Properties props = new Properties(); props.setProperty("mydomainkey","mydomainvalue"); props.setProperty("someotherkey", Arrays.toString(UUIDGenerator.randomUUID(true))); new MembersWithProperties(channel, props); channel.start(Channel.DEFAULT); Runtime.getRuntime().addShutdownHook(new Shutdown(channel)); try { Thread.sleep(Long.MAX_VALUE); }catch(InterruptedException ix) { Thread.sleep(5000);//allow everything to shutdown } }
/** * Sets the local member properties for broadcasting */ @Override public void setLocalMemberProperties(String listenHost, int listenPort, int securePort, int udpPort) { properties.setProperty("tcpListenHost", listenHost); properties.setProperty("tcpListenPort", String.valueOf(listenPort)); properties.setProperty("udpListenPort", String.valueOf(udpPort)); properties.setProperty("tcpSecurePort", String.valueOf(securePort)); try { if (localMember != null) { localMember.setHostname(listenHost); localMember.setPort(listenPort); } else { localMember = new MemberImpl(listenHost, listenPort, 0); localMember.setUniqueId(UUIDGenerator.randomUUID(true)); localMember.setPayload(getPayload()); localMember.setDomain(getDomain()); localMember.setLocal(true); } localMember.setSecurePort(securePort); localMember.setUdpPort(udpPort); localMember.getData(true, true); } catch (IOException x) { throw new IllegalArgumentException(x); } }
@Override public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException { //todo, optimize, if destination.length==1, then we can do //msg.setOptions(msg.getOptions() & (~getOptionFlag()) //and just send one message if (okToProcess(msg.getOptions()) ) { super.sendMessage(destination, msg, null); ChannelMessage confirmation = null; if ( deepclone ) confirmation = (ChannelMessage)msg.deepclone(); else confirmation = (ChannelMessage)msg.clone(); confirmation.getMessage().reset(); UUIDGenerator.randomUUID(false,confirmation.getUniqueId(),0); confirmation.getMessage().append(START_DATA,0,START_DATA.length); confirmation.getMessage().append(msg.getUniqueId(),0,msg.getUniqueId().length); confirmation.getMessage().append(END_DATA,0,END_DATA.length); super.sendMessage(destination,confirmation,payload); } else { //turn off two phase commit //this wont work if the interceptor has 0 as a flag //since there is no flag to turn off //msg.setOptions(msg.getOptions() & (~getOptionFlag())); super.sendMessage(destination, msg, payload); } }
/** * Sets the local member properties for broadcasting */ @Override public void setLocalMemberProperties(String listenHost, int listenPort, int securePort, int udpPort) { properties.setProperty("tcpListenHost",listenHost); properties.setProperty("tcpListenPort",String.valueOf(listenPort)); properties.setProperty("udpListenPort",String.valueOf(udpPort)); properties.setProperty("tcpSecurePort",String.valueOf(securePort)); try { if (localMember != null) { localMember.setHostname(listenHost); localMember.setPort(listenPort); } else { localMember = new MemberImpl(listenHost, listenPort, 0); localMember.setUniqueId(UUIDGenerator.randomUUID(true)); localMember.setPayload(getPayload()); localMember.setDomain(getDomain()); } localMember.setSecurePort(securePort); localMember.setUdpPort(udpPort); localMember.getData(true, true); }catch ( IOException x ) { throw new IllegalArgumentException(x); } }
/** * Send a message and wait for the response. * @param destination Member[] - the destination for the message, and the members you request a reply from * @param message Serializable - the message you are sending out * @param rpcOptions int - FIRST_REPLY, MAJORITY_REPLY or ALL_REPLY * @param channelOptions channel sender options * @param timeout long - timeout in milliseconds, if no reply is received within this time null is returned * @return Response[] - an array of response objects. * @throws ChannelException */ public Response[] send(Member[] destination, Serializable message, int rpcOptions, int channelOptions, long timeout) throws ChannelException { if ( destination==null || destination.length == 0 ) return new Response[0]; //avoid dead lock int sendOptions = channelOptions & ~Channel.SEND_OPTIONS_SYNCHRONIZED_ACK; RpcCollectorKey key = new RpcCollectorKey(UUIDGenerator.randomUUID(false)); RpcCollector collector = new RpcCollector(key,rpcOptions,destination.length); try { synchronized (collector) { if ( rpcOptions != NO_REPLY ) responseMap.put(key, collector); RpcMessage rmsg = new RpcMessage(rpcId, key.id, message); channel.send(destination, rmsg, sendOptions); if ( rpcOptions != NO_REPLY ) collector.wait(timeout); } } catch ( InterruptedException ix ) { Thread.currentThread().interrupt(); } finally { responseMap.remove(key); } return collector.getResponses(); }
private CoordinationMessage createElectionMsg(MemberImpl local, MemberImpl[] others, MemberImpl leader) { Membership m = new Membership(local,AbsoluteOrder.comp,true); Arrays.fill(m,others); MemberImpl[] mbrs = m.getMembers(); m.reset(); CoordinationMessage msg = new CoordinationMessage(leader, local, mbrs,new UniqueId(UUIDGenerator.randomUUID(true)), COORD_REQUEST); return msg; }
/** * Configures a set of channels to use a random domain. Use to ensure that * multiple instance of the test suite do not interfere when running on the * same machine. This may happen in a CI system or when a developer is * running tests for multiple branches in parallel. */ public static void addRandomDomain(ManagedChannel[] channels) { if (channels == null) { return; } byte[] domain = UUIDGenerator.randomUUID(false); for (ManagedChannel channel : channels) { channel.getMembershipService().setDomain(domain); DomainFilterInterceptor filter = new DomainFilterInterceptor(); filter.setDomain(domain); channel.addInterceptor(filter); } }
@Before public void setUp() throws Exception { for (int i = 0; i < channels.length; i++) { channels[i] = new GroupChannel(); channels[i].getMembershipService().setPayload( ("Channel-" + (i + 1)).getBytes("ASCII")); listeners[i] = new TestMbrListener( ("Listener-" + (i + 1))); channels[i].addMembershipListener(listeners[i]); DomainFilterInterceptor filter = new DomainFilterInterceptor(); filter.setDomain(UUIDGenerator.randomUUID(false)); channels[i].addInterceptor(filter); } }
/** * Send a message and wait for the response. * * @param destination * Member[] - the destination for the message, and the members * you request a reply from * @param message * Serializable - the message you are sending out * @param rpcOptions * int - FIRST_REPLY, MAJORITY_REPLY or ALL_REPLY * @param channelOptions * channel sender options * @param timeout * long - timeout in milliseconds, if no reply is received within * this time null is returned * @return Response[] - an array of response objects. * @throws ChannelException */ public Response[] send(Member[] destination, Serializable message, int rpcOptions, int channelOptions, long timeout) throws ChannelException { if (destination == null || destination.length == 0) return new Response[0]; // avoid dead lock int sendOptions = channelOptions & ~Channel.SEND_OPTIONS_SYNCHRONIZED_ACK; RpcCollectorKey key = new RpcCollectorKey(UUIDGenerator.randomUUID(false)); RpcCollector collector = new RpcCollector(key, rpcOptions, destination.length); try { synchronized (collector) { if (rpcOptions != NO_REPLY) responseMap.put(key, collector); RpcMessage rmsg = new RpcMessage(rpcId, key.id, message); channel.send(destination, rmsg, sendOptions); if (rpcOptions != NO_REPLY) collector.wait(timeout); } } catch (InterruptedException ix) { Thread.currentThread().interrupt(); } finally { responseMap.remove(key); } return collector.getResponses(); }
private CoordinationMessage createElectionMsg(MemberImpl local, MemberImpl[] others, MemberImpl leader) { Membership m = new Membership(local, AbsoluteOrder.comp, true); Arrays.fill(m, others); MemberImpl[] mbrs = m.getMembers(); m.reset(); CoordinationMessage msg = new CoordinationMessage(leader, local, mbrs, new UniqueId(UUIDGenerator.randomUUID(true)), COORD_REQUEST); return msg; }
/** * Send a message and wait for the response. * @param destination Member[] - the destination for the message, and the members you request a reply from * @param message Serializable - the message you are sending out * @param rpcOptions int - FIRST_REPLY, MAJORITY_REPLY or ALL_REPLY * @param channelOptions channel sender options * @param timeout long - timeout in milliseconds, if no reply is received within this time null is returned * @return Response[] - an array of response objects. * @throws ChannelException */ public Response[] send(Member[] destination, Serializable message, int rpcOptions, int channelOptions, long timeout) throws ChannelException { if ( destination==null || destination.length == 0 ) return new Response[0]; //avoid dead lock int sendOptions = channelOptions & ~Channel.SEND_OPTIONS_SYNCHRONIZED_ACK; RpcCollectorKey key = new RpcCollectorKey(UUIDGenerator.randomUUID(false)); RpcCollector collector = new RpcCollector(key,rpcOptions,destination.length); try { synchronized (collector) { if ( rpcOptions != NO_REPLY ) responseMap.put(key, collector); RpcMessage rmsg = new RpcMessage(rpcId, key.id, message); channel.send(destination, rmsg, sendOptions); if ( rpcOptions != NO_REPLY ) collector.wait(timeout); } } catch ( InterruptedException ix ) { Thread.currentThread().interrupt(); }finally { responseMap.remove(key); } return collector.getResponses(); }
/** * Send a message and wait for the response. * @param destination Member[] - the destination for the message, and the members you request a reply from * @param message Serializable - the message you are sending out * @param rpcOptions int - FIRST_REPLY, MAJORITY_REPLY or ALL_REPLY * @param channelOptions channel sender options * @param timeout long - timeout in milliseconds, if no reply is received within this time null is returned * @return Response[] - an array of response objects. * @throws ChannelException */ public Response[] send(Member[] destination, Serializable message, int rpcOptions, int channelOptions, long timeout) throws ChannelException { if ( destination==null || destination.length == 0 ) return new Response[0]; //avoid dead lock int sendOptions = channelOptions & ~Channel.SEND_OPTIONS_SYNCHRONIZED_ACK; RpcCollectorKey key = new RpcCollectorKey(UUIDGenerator.randomUUID(false)); RpcCollector collector = new RpcCollector(key,rpcOptions,destination.length,timeout); try { synchronized (collector) { if ( rpcOptions != NO_REPLY ) responseMap.put(key, collector); RpcMessage rmsg = new RpcMessage(rpcId, key.id, message); channel.send(destination, rmsg, sendOptions); if ( rpcOptions != NO_REPLY ) collector.wait(timeout); } } catch ( InterruptedException ix ) { Thread.currentThread().interrupt(); }finally { responseMap.remove(key); } return collector.getResponses(); }