/** @return a clone of this object */ @Override public Object clone() { UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes(); attributes.setSendDelaySec( this.getSendDelaySec() ); attributes.setMaxIdleTimeSec( this.getMaxIdleTimeSec() ); attributes.setServiceName( this.getServiceName() ); attributes.setServicePort( this.getServicePort() ); attributes.setUdpDiscoveryAddr( this.getUdpDiscoveryAddr() ); attributes.setUdpDiscoveryPort( this.getUdpDiscoveryPort() ); attributes.setDark( this.isDark() ); return attributes; }
/** * This sends a message broadcasting out that the host and port is available for connections. * <p> * It uses the vmid as the requesterDI * @param host * @param port * @param cacheNames * @throws IOException */ public void passiveBroadcast( String host, int port, ArrayList<String> cacheNames ) throws IOException { passiveBroadcast( host, port, cacheNames, CacheInfo.listenerId ); }
/** * This sends a message broadcasting our that the host and port is no longer available. * <p> * It uses the vmid as the requesterID * <p> * @param host host * @param port port * @param cacheNames names of the cache regions * @throws IOException on error */ public void removeBroadcast( String host, int port, ArrayList<String> cacheNames ) throws IOException { removeBroadcast( host, port, cacheNames, CacheInfo.listenerId ); }
/** * Test sending a live messages. * <p> * @throws Exception on error */ public void testPassiveBroadcast() throws Exception { // SETUP ArrayList<String> cacheNames = new ArrayList<String>(); // DO WORK sender.passiveBroadcast( SENDING_HOST, SENDING_PORT, cacheNames, 1L ); // VERIFY // grab the sent message Object obj = receiver.waitForMessage() ; assertTrue( "unexpected crap received", obj instanceof UDPDiscoveryMessage ); UDPDiscoveryMessage msg = (UDPDiscoveryMessage) obj; // disabled test because of JCS-89 // assertEquals( "wrong host", SENDING_HOST, msg.getHost() ); assertEquals( "wrong port", SENDING_PORT, msg.getPort() ); assertEquals( "wrong message type", BroadcastType.PASSIVE, msg.getMessageType() ); }
/** * Test sending a request broadcast. * <p> * @throws Exception on error */ public void testRequestBroadcast() throws Exception { // DO WORK sender.requestBroadcast(); // VERIFY // grab the sent message Object obj = receiver.waitForMessage(); assertTrue( "unexpected crap received", obj instanceof UDPDiscoveryMessage ); UDPDiscoveryMessage msg = (UDPDiscoveryMessage) obj; assertEquals( "wrong message type", BroadcastType.REQUEST, msg.getMessageType() ); } }
/** * Set up the receiver. Maybe better to just code sockets here? Set up the sender for sending * the message. * <p> * @throws Exception on error */ @Override protected void setUp() throws Exception { super.setUp(); receiver = new UDPDiscoveryReceiver( null, ADDRESS, PORT ); sender = new UDPDiscoverySender( ADDRESS, PORT ); }
/** * @see org.apache.commons.jcs.engine.behavior.IRequireScheduler#setScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) */ @Override public void setScheduledExecutorService(ScheduledExecutorService scheduledExecutor) { if (sender != null) { scheduledExecutor.scheduleAtFixedRate(sender, 0, 15, TimeUnit.SECONDS); } /** removes things that have been idle for too long */ UDPCleanupRunner cleanup = new UDPCleanupRunner( this ); // I'm going to use this as both, but it could happen // that something could hang around twice the time using this as the // delay and the idle time. scheduledExecutor.scheduleAtFixedRate(cleanup, 0, getUdpDiscoveryAttributes().getMaxIdleTimeSec(), TimeUnit.SECONDS); }
/** * Adds a region to the list that is participating in discovery. * <p> * @param cacheName */ public void addParticipatingCacheName( String cacheName ) { cacheNames.add( cacheName ); sender.setCacheNames( getCacheNames() ); }
/** * Just being careful about closing the socket. * <p> * @throws Throwable */ @Override protected void finalize() throws Throwable { super.finalize(); destroy(); }
/** * Removes a listener. * <p> * @param listener * @return true if it was in the set */ public boolean removeDiscoveryListener( IDiscoveryListener listener ) { return getDiscoveryListeners().remove( listener ); } }
/** @return a clone of this object */ @Override public UDPDiscoveryAttributes clone() { UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes(); attributes.setSendDelaySec( this.getSendDelaySec() ); attributes.setMaxIdleTimeSec( this.getMaxIdleTimeSec() ); attributes.setServiceName( this.getServiceName() ); attributes.setServicePort( this.getServicePort() ); attributes.setUdpDiscoveryAddr( this.getUdpDiscoveryAddr() ); attributes.setUdpDiscoveryPort( this.getUdpDiscoveryPort() ); attributes.setDark( this.isDark() ); return attributes; }
/** * Test sending a live messages. * <p> * @throws Exception on error */ public void testPassiveBroadcast() throws Exception { // SETUP ArrayList<String> cacheNames = new ArrayList<String>(); // DO WORK sender.passiveBroadcast( SENDING_HOST, SENDING_PORT, cacheNames, 1L ); // VERIFY // grab the sent message Object obj = receiver.waitForMessage() ; assertTrue( "unexpected crap received", obj instanceof UDPDiscoveryMessage ); UDPDiscoveryMessage msg = (UDPDiscoveryMessage) obj; // disabled test because of JCS-89 // assertEquals( "wrong host", SENDING_HOST, msg.getHost() ); assertEquals( "wrong port", SENDING_PORT, msg.getPort() ); assertEquals( "wrong message type", BroadcastType.PASSIVE, msg.getMessageType() ); }
/** * Test sending a request broadcast. * <p> * @throws Exception on error */ public void testRequestBroadcast() throws Exception { // DO WORK sender.requestBroadcast(); // VERIFY // grab the sent message Object obj = receiver.waitForMessage(); assertTrue( "unexpected crap received", obj instanceof UDPDiscoveryMessage ); UDPDiscoveryMessage msg = (UDPDiscoveryMessage) obj; assertEquals( "wrong message type", BroadcastType.REQUEST, msg.getMessageType() ); } }
/** * Set up the receiver. Maybe better to just code sockets here? Set up the sender for sending * the message. * <p> * @throws Exception on error */ @Override protected void setUp() throws Exception { super.setUp(); receiver = new UDPDiscoveryReceiver( null, ADDRESS, PORT ); sender = new UDPDiscoverySender( ADDRESS, PORT ); }
/** * @see org.apache.commons.jcs.engine.behavior.IRequireScheduler#setScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) */ @Override public void setScheduledExecutorService(ScheduledExecutorService scheduledExecutor) { if (sender != null) { scheduledExecutor.scheduleAtFixedRate(sender, 0, 15, TimeUnit.SECONDS); } /** removes things that have been idle for too long */ UDPCleanupRunner cleanup = new UDPCleanupRunner( this ); // I'm going to use this as both, but it could happen // that something could hang around twice the time using this as the // delay and the idle time. scheduledExecutor.scheduleAtFixedRate(cleanup, 0, getUdpDiscoveryAttributes().getMaxIdleTimeSec(), TimeUnit.SECONDS); }
/** * Adds a region to the list that is participating in discovery. * <p> * @param cacheName */ public void addParticipatingCacheName( String cacheName ) { cacheNames.add( cacheName ); sender.setCacheNames( getCacheNames() ); }
/** * This sends a message broadcasting out that the host and port is available for connections. * <p> * It uses the vmid as the requesterDI * @param host * @param port * @param cacheNames * @throws IOException */ public void passiveBroadcast( String host, int port, ArrayList<String> cacheNames ) throws IOException { passiveBroadcast( host, port, cacheNames, CacheInfo.listenerId ); }
/** * This sends a message broadcasting our that the host and port is no longer available. * <p> * It uses the vmid as the requesterID * <p> * @param host host * @param port port * @param cacheNames names of the cache regions * @throws IOException on error */ public void removeBroadcast( String host, int port, ArrayList<String> cacheNames ) throws IOException { removeBroadcast( host, port, cacheNames, CacheInfo.listenerId ); }