/** @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; }
sender = new UDPDiscoverySender( attributes.getUdpDiscoveryAddr(), attributes.getUdpDiscoveryPort() ); sender.passiveBroadcast( attributes.getServiceAddress(), attributes.getServicePort(), cacheNames ); log.error( "Problem calling the UDP Discovery Sender [" + attributes.getUdpDiscoveryAddr() + ":" + attributes.getUdpDiscoveryPort() + "]", e );
/** * @return string for debugging purposes. */ @Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append( "\n UDPDiscoveryAttributes" ); buf.append( "\n ServiceName = [" + getServiceName() + "]" ); buf.append( "\n ServiceAddress = [" + getServiceAddress() + "]" ); buf.append( "\n ServicePort = [" + getServicePort() + "]" ); buf.append( "\n UdpDiscoveryAddr = [" + getUdpDiscoveryAddr() + "]" ); buf.append( "\n UdpDiscoveryPort = [" + getUdpDiscoveryPort() + "]" ); buf.append( "\n SendDelaySec = [" + getSendDelaySec() + "]" ); buf.append( "\n MaxIdleTimeSec = [" + getMaxIdleTimeSec() + "]" ); buf.append( "\n IsDark = [" + isDark() + "]" ); return buf.toString(); } }
UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes(); attributes.setUdpDiscoveryAddr( discoveryAddress ); attributes.setUdpDiscoveryPort( discoveryPort ); attributes.setServicePort( servicePort );
throws Exception UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes(); attributes.setUdpDiscoveryAddr( "228.5.6.7" ); attributes.setUdpDiscoveryPort( 6789 ); attributes.setServicePort( 1000 ); UDPDiscoveryReceiver receiver = new UDPDiscoveryReceiver( service, attributes.getUdpDiscoveryAddr(), attributes .getUdpDiscoveryPort() ); Thread t = new Thread( receiver ); t.start(); UDPDiscoverySender sender = new UDPDiscoverySender( attributes.getUdpDiscoveryAddr(), attributes .getUdpDiscoveryPort() );
udpDiscoveryAttributes = (UDPDiscoveryAttributes) attributes.clone(); udpDiscoveryAttributes.setServiceAddress( HostNameUtil.getLocalHostAddress() ); receiver = new UDPDiscoveryReceiver( this, getUdpDiscoveryAttributes().getUdpDiscoveryAddr(), getUdpDiscoveryAttributes().getUdpDiscoveryPort() ); udpReceiverThread = new Thread( receiver ); udpReceiverThread.setDaemon( true ); + getUdpDiscoveryAttributes().getUdpDiscoveryAddr() + "] port [" + getUdpDiscoveryAttributes().getUdpDiscoveryPort() + "] we won't be able to find any other caches", e );
/** * @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); }
UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes(); attributes.setUdpDiscoveryAddr( discoveryAddress ); attributes.setUdpDiscoveryPort( discoveryPort ); attributes.setServicePort( servicePort );
throws Exception UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes(); attributes.setUdpDiscoveryAddr( "228.5.6.7" ); attributes.setUdpDiscoveryPort( 6789 ); attributes.setServicePort( 1000 ); UDPDiscoveryReceiver receiver = new UDPDiscoveryReceiver( service, attributes.getUdpDiscoveryAddr(), attributes .getUdpDiscoveryPort() ); Thread t = new Thread( receiver ); t.start(); UDPDiscoverySender sender = new UDPDiscoverySender( attributes.getUdpDiscoveryAddr(), attributes .getUdpDiscoveryPort() );
/** * @return string for debugging purposes. */ @Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append( "\n UDPDiscoveryAttributes" ); buf.append( "\n ServiceName = [" + getServiceName() + "]" ); buf.append( "\n ServiceAddress = [" + getServiceAddress() + "]" ); buf.append( "\n ServicePort = [" + getServicePort() + "]" ); buf.append( "\n UdpDiscoveryAddr = [" + getUdpDiscoveryAddr() + "]" ); buf.append( "\n UdpDiscoveryPort = [" + getUdpDiscoveryPort() + "]" ); buf.append( "\n SendDelaySec = [" + getSendDelaySec() + "]" ); buf.append( "\n MaxIdleTimeSec = [" + getMaxIdleTimeSec() + "]" ); buf.append( "\n IsDark = [" + isDark() + "]" ); return buf.toString(); } }
/** * @param attributes */ public UDPDiscoveryService( UDPDiscoveryAttributes attributes) { udpDiscoveryAttributes = (UDPDiscoveryAttributes) attributes.clone(); try { // todo, you should be able to set this udpDiscoveryAttributes.setServiceAddress( HostNameUtil.getLocalHostAddress() ); } catch ( UnknownHostException e ) { log.error( "Couldn't get localhost address", e ); } try { // todo need some kind of recovery here. receiver = new UDPDiscoveryReceiver( this, getUdpDiscoveryAttributes().getUdpDiscoveryAddr(), getUdpDiscoveryAttributes().getUdpDiscoveryPort() ); } catch ( IOException e ) { log.error( "Problem creating UDPDiscoveryReceiver, address [" + getUdpDiscoveryAttributes().getUdpDiscoveryAddr() + "] port [" + getUdpDiscoveryAttributes().getUdpDiscoveryPort() + "] we won't be able to find any other caches", e ); } // create a sender thread sender = new UDPDiscoverySenderThread( getUdpDiscoveryAttributes(), getCacheNames() ); }
/** * @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); }
/** @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; }
/** Verify that the list is updated. */ public void testAddOrUpdateService_NotInList() { // SETUP String host = "228.5.6.7"; int port = 6789; UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes(); attributes.setUdpDiscoveryAddr( host ); attributes.setUdpDiscoveryPort( port ); attributes.setServicePort( 1000 ); // create the service UDPDiscoveryService service = new UDPDiscoveryService( attributes ); service.addParticipatingCacheName( "testCache1" ); MockDiscoveryListener discoveryListener = new MockDiscoveryListener(); service.addDiscoveryListener( discoveryListener ); DiscoveredService discoveredService = new DiscoveredService(); discoveredService.setServiceAddress( host ); discoveredService.setCacheNames( new ArrayList<String>() ); discoveredService.setServicePort( 1000 ); discoveredService.setLastHearFromTime( 100 ); // DO WORK service.addOrUpdateService( discoveredService ); // VERIFY assertTrue( "Service should be in the service list.", service.getDiscoveredServices() .contains( discoveredService ) ); assertTrue( "Service should be in the listener list.", discoveryListener.discoveredServices .contains( discoveredService ) ); }
sender = new UDPDiscoverySender( attributes.getUdpDiscoveryAddr(), attributes.getUdpDiscoveryPort() ); sender.removeBroadcast( attributes.getServiceAddress(), attributes.getServicePort(), cacheNames );
/** Verify that the list is updated. */ public void testAddOrUpdateService_NotInList() { // SETUP String host = "228.5.6.7"; int port = 6789; UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes(); attributes.setUdpDiscoveryAddr( host ); attributes.setUdpDiscoveryPort( port ); attributes.setServicePort( 1000 ); // create the service UDPDiscoveryService service = new UDPDiscoveryService( attributes ); service.startup(); service.addParticipatingCacheName( "testCache1" ); MockDiscoveryListener discoveryListener = new MockDiscoveryListener(); service.addDiscoveryListener( discoveryListener ); DiscoveredService discoveredService = new DiscoveredService(); discoveredService.setServiceAddress( host ); discoveredService.setCacheNames( new ArrayList<String>() ); discoveredService.setServicePort( 1000 ); discoveredService.setLastHearFromTime( 100 ); // DO WORK service.addOrUpdateService( discoveredService ); // VERIFY assertTrue( "Service should be in the service list.", service.getDiscoveredServices() .contains( discoveredService ) ); assertTrue( "Service should be in the listener list.", discoveryListener.discoveredServices .contains( discoveredService ) ); }
sender = new UDPDiscoverySender( attributes.getUdpDiscoveryAddr(), attributes.getUdpDiscoveryPort() ); sender.passiveBroadcast( attributes.getServiceAddress(), attributes.getServicePort(), cacheNames ); log.error( "Problem calling the UDP Discovery Sender [" + attributes.getUdpDiscoveryAddr() + ":" + attributes.getUdpDiscoveryPort() + "]", e );
UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes(); attributes.setUdpDiscoveryAddr( host ); attributes.setUdpDiscoveryPort( port ); attributes.setServicePort( 1000 );
log.debug( "Creating sender thread for discoveryAddress = [" + attributes.getUdpDiscoveryAddr() + "] and discoveryPort = [" + attributes.getUdpDiscoveryPort() + "] myHostName = [" + attributes.getServiceAddress() + "] and port = [" + attributes.getServicePort() + "]" ); sender = new UDPDiscoverySender( attributes.getUdpDiscoveryAddr(), attributes.getUdpDiscoveryPort() ); sender.requestBroadcast();
UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes(); attributes.setUdpDiscoveryAddr( host ); attributes.setUdpDiscoveryPort( port ); attributes.setServicePort( 1000 );