directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r782980 [5/8] - in /directory/sandbox/slp/src/main/java/org/apache/directory/slp: ./ codec/ extensions/ impl/ impl/da/ impl/filter/ messages/
Date Tue, 09 Jun 2009 12:50:47 GMT
Modified: directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPDaemonImpl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPDaemonImpl.java?rev=782980&r1=782979&r2=782980&view=diff
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPDaemonImpl.java (original)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPDaemonImpl.java Tue Jun  9 12:50:45 2009
@@ -19,7 +19,6 @@
  */
 package org.apache.directory.slp.impl;
 
-
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.UnknownHostException;
@@ -73,17 +72,14 @@
 	 * 
 	 * String scope -> List of ServiceURLs services. //?? Service, not URLS...
 	 */
-	private Map<String,List<Service>> registeredServices = new HashMap<String,List<Service>>();
+	private final Map<String, List<Service>> registeredServices = new HashMap<String, List<Service>>();
 
 	/**
 	 * Sorted set for disposal of services which lifetimes have expired:
 	 * 
 	 * Long expirationTimestamp -> ServiceURL service.
 	 */
-	private SortedMap<Long,ServiceURL> serviceDisposalQueue = new TreeMap<Long,ServiceURL>();
-
-
-
+	private final SortedMap<Long, ServiceURL> serviceDisposalQueue = new TreeMap<Long, ServiceURL>();
 
 	/**
 	 * create a new SLPDaemon instance.
@@ -94,7 +90,7 @@
 	public SLPDaemonImpl() throws Exception {
 		new ServiceDisposalThread();
 		SLPCore.platform.logDebug("jSLP daemon starting ...");
-		running=true;
+		running = true;
 	}
 
 	/**
@@ -105,12 +101,13 @@
 	 *            the ServiceRegistration.
 	 */
 	private void registerService(final ServiceRegistrationMessage reg) {
-		// prevent registrations from being sent to the same DA multiple times when in multiple scopes
-		List<String> handledDAs = new ArrayList<String>();
+		// prevent registrations from being sent to the same DA multiple times
+		// when in multiple scopes
+		final List<String> handledDAs = new ArrayList<String>();
 
-		Service service = new Service(reg);
-		String[] scopes = reg.getScopes();
-		for (int i=0;i<scopes.length;i++) {
+		final Service service = new Service(reg);
+		final String[] scopes = reg.getScopes();
+		for (int i = 0; i < scopes.length; i++) {
 			String scope = reg.getScopes()[i];
 			scope = scope.toLowerCase().trim();
 			synchronized (registeredServices) {
@@ -119,17 +116,19 @@
 			}
 			if (reg.getServiceURL().getLifetime() > ServiceURL.LIFETIME_PERMANENT) {
 				synchronized (serviceDisposalQueue) {
-					long next = System.currentTimeMillis()
-					+ (reg.getServiceURL().getLifetime() * 1000);
-					ArrayList<Long> keys = new ArrayList<Long>(serviceDisposalQueue
-							.keySet());
-					for (Iterator iter = keys.iterator(); iter.hasNext();) {
-						Object key = iter.next();
-						if (serviceDisposalQueue.get(key).equals(reg.getServiceURL())) {
+					final long next = System.currentTimeMillis()
+							+ reg.getServiceURL().getLifetime() * 1000;
+					final ArrayList<Long> keys = new ArrayList<Long>(
+							serviceDisposalQueue.keySet());
+					for (final Iterator iter = keys.iterator(); iter.hasNext();) {
+						final Object key = iter.next();
+						if (serviceDisposalQueue.get(key).equals(
+								reg.getServiceURL())) {
 							serviceDisposalQueue.remove(key);
 						}
 					}
-					serviceDisposalQueue.put(new Long(next), reg.getServiceURL());
+					serviceDisposalQueue.put(new Long(next), reg
+							.getServiceURL());
 					serviceDisposalQueue.notifyAll();
 				}
 			}
@@ -137,64 +136,69 @@
 			SLPCore.platform.logTraceReg("REGISTERED " + reg.getServiceURL());
 
 			// register the service with all known DAs in the scopes
-			List<String> daList = (List<String>) SLPCore.dAs.get(scope);
+			List<String> daList = SLPCore.dAs.get(scope);
 
 			// no DA for the scope known ?
 			// try to find one
-			//could this lead to unnecessary timeouts???
+			// could this lead to unnecessary timeouts???
 			if ((daList == null || daList.isEmpty()) && !SLPCore.noDiscovery) {
 				try {
-					SLPCore.daLookup(new String[] { (String) scope });
+					SLPCore.daLookup(new String[] { scope });
 
 					// wait a short time for incoming replies
 					synchronized (SLPCore.dAs) {
 						try {
 							SLPCore.dAs.wait(SLPCore.CONFIG.getWaitTime());
-						} catch (InterruptedException e) {
+						} catch (final InterruptedException e) {
 						}
 					}
 					daList = SLPCore.dAs.get(scope);
-				} catch (ServiceLocationException sle) {
+				} catch (final ServiceLocationException sle) {
 					SLPCore.platform.logError(sle.getMessage(), sle
 							.fillInStackTrace());
 				}
 			}
 
-
-
-
 			if (daList != null && !daList.isEmpty()) {
-				final String[] dAs = (String[]) daList
-				.toArray(new String[daList.size()]);
+				final String[] dAs = daList.toArray(new String[daList.size()]);
 				for (int j = 0; j < dAs.length; j++) {
-					try{
-						if (handledDAs.contains(dAs[j])){
+					try {
+						if (handledDAs.contains(dAs[j])) {
 							continue;
 						}
 						handledDAs.add(dAs[j]);
-						// if the ip is within the framework, i.e. DA and SA are running at the same time, then pass the reg on internally
-						if (SLPUtils.arrayToList(SLPCore.myIPs).contains(dAs[j])){
-							if (SLPCore.getDirectoryAgentDaemon()!=null){
-								if (SLPCore.getDirectoryAgentDaemon().isKnownService(service)){
-									SLPCore.getDirectoryAgentDaemon().updateServiceEntry(reg);
+						// if the ip is within the framework, i.e. DA and SA are
+						// running at the same time, then pass the reg on
+						// internally
+						if (SLPUtils.arrayToList(SLPCore.myIPs)
+								.contains(dAs[j])) {
+							if (SLPCore.getDirectoryAgentDaemon() != null) {
+								if (SLPCore.getDirectoryAgentDaemon()
+										.isKnownService(service)) {
+									SLPCore.getDirectoryAgentDaemon()
+											.updateServiceEntry(reg);
 								} else {
-									SLPCore.getDirectoryAgentDaemon().registerService(reg);
+									SLPCore.getDirectoryAgentDaemon()
+											.registerService(reg);
 								}
 							} else {
-								// what? no daDaemon running?? must remove the ip from the list
-								SLPUtils.removeValueFromAll(SLPCore.dAs, (reg).getServiceURL().toString());
-								SLPCore.dASPIs.remove((reg).getServiceURL().toString());
+								// what? no daDaemon running?? must remove the
+								// ip from the list
+								SLPUtils.removeValueFromAll(SLPCore.dAs, reg
+										.getServiceURL().toString());
+								SLPCore.dASPIs.remove(reg.getServiceURL()
+										.toString());
 
 							}
 						} else {
 							announceService(dAs[j], reg);
 						}
 
-					} catch (ServiceLocationException e) {
-						if (e.getErrorCode()==ServiceLocationException.INVALID_REGISTRATION){
+					} catch (final ServiceLocationException e) {
+						if (e.getErrorCode() == ServiceLocationException.INVALID_REGISTRATION) {
 							return;
 						}
-						
+
 						// remove DA from list
 						SLPUtils.removeValueFromAll(SLPCore.dAs, dAs[i]);
 						SLPCore.dASPIs.remove(dAs[i]);
@@ -207,21 +211,26 @@
 
 	}
 
-	private void updateService(final ServiceRegistrationMessage reg) throws ServiceLocationException{
+	private void updateService(final ServiceRegistrationMessage reg)
+			throws ServiceLocationException {
 
-		// fresh flag is set and the message comes from the framework, considered safe for now...
+		// fresh flag is set and the message comes from the framework,
+		// considered safe for now...
 		Service registeredService = null;
-		Service newService = new Service(reg);
+		final Service newService = new Service(reg);
 		boolean found = false;
-		for (int i=0;i<reg.getScopes().length&&!found; i++) {
-			List<Service> services = registeredServices.get(reg.getScopes()[i].toLowerCase().trim());
+		for (int i = 0; i < reg.getScopes().length && !found; i++) {
+			final List<Service> services = registeredServices.get(reg
+					.getScopes()[i].toLowerCase().trim());
 			if (services == null) {
 				continue;
 			}
 
-			for (Iterator<Service> srvs = services.iterator(); srvs.hasNext();) {
-				Service service = srvs.next();
-				if (service.getURL().toString().equals(reg.getServiceURL().toString())){
+			for (final Iterator<Service> srvs = services.iterator(); srvs
+					.hasNext();) {
+				final Service service = srvs.next();
+				if (service.getURL().toString().equals(
+						reg.getServiceURL().toString())) {
 					registeredService = service;
 					found = true;
 					break;
@@ -229,40 +238,50 @@
 			}
 		}
 
-		if (registeredService==null){
-			throw new ServiceLocationException(ServiceLocationException.INVALID_UPDATE,"No service to update...");
+		if (registeredService == null) {
+			throw new ServiceLocationException(
+					ServiceLocationException.INVALID_UPDATE,
+					"No service to update...");
 		}
 
-		Dictionary<String,Object> registeredAttributes = registeredService.getAttributes();
-		Dictionary<String,Object> newAttributes = SLPUtils.stringArrayToDict(reg.getAttrList());
-		Enumeration<String> keys = newAttributes.keys();
-		while (keys.hasMoreElements()){
-			String key = keys.nextElement();
+		final Dictionary<String, Object> registeredAttributes = registeredService
+				.getAttributes();
+		final Dictionary<String, Object> newAttributes = SLPUtils
+				.stringArrayToDict(reg.getAttrList());
+		final Enumeration<String> keys = newAttributes.keys();
+		while (keys.hasMoreElements()) {
+			final String key = keys.nextElement();
 			registeredAttributes.remove(key);
 			registeredAttributes.put(key, newAttributes.get(key));
 		}
 		newService.setAttributes(registeredAttributes);
 
-		final String[] scopes = (String[]) registeredServices.keySet().toArray(
+		final String[] scopes = registeredServices.keySet().toArray(
 				new String[registeredServices.size()]);
 		for (int i = 0; i < scopes.length; i++) {
-			final List<Service> tmp = registeredServices.get(scopes[i].toLowerCase());
-			final Service[] services = tmp.toArray(new Service[tmp
-			                                                   .size()]);
+			final List<Service> tmp = registeredServices.get(scopes[i]
+					.toLowerCase());
+			final Service[] services = tmp.toArray(new Service[tmp.size()]);
 
 			for (int j = 0; j < services.length; j++) {
 				if (reg.getServiceURL().matches(services[j].getURL())) {
-					List<String> daList = SLPCore.dAs.get(scopes[i].toLowerCase());
+					final List<String> daList = SLPCore.dAs.get(scopes[i]
+							.toLowerCase());
 					if (daList != null) {
-						for (String dA : daList) {
+						for (final String dA : daList) {
 
-							// if there is a local DA in the same framework, deregister the service directly from there
-							if (SLPUtils.arrayToList(SLPCore.myIPs).contains(dA)){
-								if (SLPCore.getDirectoryAgentDaemon()!=null){
-									SLPCore.getDirectoryAgentDaemon().updateServiceEntry(reg);
-								}  else {
-									// what? no daDaemon running?? must remove the ip from the list
-									SLPUtils.removeValueFromAll(SLPCore.dAs, dA);
+							// if there is a local DA in the same framework,
+							// deregister the service directly from there
+							if (SLPUtils.arrayToList(SLPCore.myIPs)
+									.contains(dA)) {
+								if (SLPCore.getDirectoryAgentDaemon() != null) {
+									SLPCore.getDirectoryAgentDaemon()
+											.updateServiceEntry(reg);
+								} else {
+									// what? no daDaemon running?? must remove
+									// the ip from the list
+									SLPUtils
+											.removeValueFromAll(SLPCore.dAs, dA);
 									SLPCore.dASPIs.remove(dA);
 
 								}
@@ -271,23 +290,21 @@
 
 							// update all known remote DAs
 
-
 							if (SLPCore.CONFIG.getSecurityEnabled()) {
-								List spiList = (List) SLPCore.dASPIs
-								.get(dA);
+								final List spiList = SLPCore.dASPIs.get(dA);
 								reg.sign(SLPUtils.listToStringArray(spiList));
 							}
 
 							announceUpdatedService(dA, reg, newService);
 
-
-						} 
+						}
 					}
 
 					synchronized (registeredServices) {
 						SLPUtils.removeValue(registeredServices, scopes[i],
 								services[j]);
-						SLPUtils.addValue(registeredServices, scopes[i], newService);
+						SLPUtils.addValue(registeredServices, scopes[i],
+								newService);
 					}
 					break;
 				}
@@ -295,8 +312,6 @@
 		}
 	}
 
-
-
 	/**
 	 * deregister a service from the SLP framework. Deregisters from all DAs
 	 * within the scopes and from the local service cache.
@@ -306,34 +321,43 @@
 	 * @throws ServiceLocationException
 	 */
 	private void deregisterService(final ServiceDeregistrationMessage dereg)
-	throws ServiceLocationException {
+			throws ServiceLocationException {
 
-		final String[] scopes = (String[]) registeredServices.keySet().toArray(
+		final String[] scopes = registeredServices.keySet().toArray(
 				new String[registeredServices.size()]);
-		List<String> handledDAs = new ArrayList<String>();
+		final List<String> handledDAs = new ArrayList<String>();
 		for (int i = 0; i < scopes.length; i++) {
-			final List<Service> tmp = registeredServices.get(scopes[i].toLowerCase());
-			final Service[] services = tmp.toArray(new Service[tmp
-			                                                   .size()]);
+			final List<Service> tmp = registeredServices.get(scopes[i]
+					.toLowerCase());
+			final Service[] services = tmp.toArray(new Service[tmp.size()]);
 
 			for (int j = 0; j < services.length; j++) {
 				if (dereg.getServiceURL().matches(services[j].getURL())) {
-					List<String> daList = SLPCore.dAs.get(scopes[i].toLowerCase());
+					final List<String> daList = SLPCore.dAs.get(scopes[i]
+							.toLowerCase());
 					if (daList != null) {
-						for (String dA : daList) {
-							if (handledDAs.contains(dA)){
+						for (final String dA : daList) {
+							if (handledDAs.contains(dA)) {
 								continue;
 							}
 							handledDAs.add(dA);
 							try {
-								// if there is a local DA in the same framework, deregister the service directly from there
-								if (SLPUtils.arrayToList(SLPCore.myIPs).contains(dA)){
-									if (SLPCore.getDirectoryAgentDaemon()!=null){
-										SLPCore.getDirectoryAgentDaemon().deregisterService(dereg);
-									}  else {
-										// what? no daDaemon running?? must remove the ip from the list
-										SLPUtils.removeValueFromAll(SLPCore.dAs, (dereg).getServiceURL().toString());
-										SLPCore.dASPIs.remove((dereg).getServiceURL().toString());
+								// if there is a local DA in the same framework,
+								// deregister the service directly from there
+								if (SLPUtils.arrayToList(SLPCore.myIPs)
+										.contains(dA)) {
+									if (SLPCore.getDirectoryAgentDaemon() != null) {
+										SLPCore.getDirectoryAgentDaemon()
+												.deregisterService(dereg);
+									} else {
+										// what? no daDaemon running?? must
+										// remove the ip from the list
+										SLPUtils.removeValueFromAll(
+												SLPCore.dAs, dereg
+														.getServiceURL()
+														.toString());
+										SLPCore.dASPIs.remove(dereg
+												.getServiceURL().toString());
 
 									}
 									return;
@@ -341,28 +365,29 @@
 
 								// deregister from all known remote DAs
 
-								ServiceDeregistrationMessage dadereg = new ServiceDeregistrationMessage();
+								final ServiceDeregistrationMessage dadereg = new ServiceDeregistrationMessage();
 								dadereg.setLocale(dereg.getLocale());
 								dadereg.setMulticast(false);
 								dadereg.setScopes(dereg.getScopes());
 								dadereg.setServiceURL(dereg.getServiceURL());
 								dadereg.setTags(dereg.getTags());
 
-								InetSocketAddress address = new InetSocketAddress(InetAddress.getByName(dA),SLPCore.SLP_PORT);
+								final InetSocketAddress address = new InetSocketAddress(
+										InetAddress.getByName(dA),
+										SLPCore.SLP_PORT);
 								dadereg.setXid(SLPCore.nextXid());
 								if (SLPCore.CONFIG.getSecurityEnabled()) {
-									List spiList = (List) SLPCore.dASPIs
-									.get(dA);
+									final List spiList = SLPCore.dASPIs.get(dA);
 									dadereg.sign(spiList);
 								}
-								AbstractSLPReplyMessage reply = new ServiceReplyMessage();
-								new AnnouncerThread(address,dadereg,reply);
+								final AbstractSLPReplyMessage reply = new ServiceReplyMessage();
+								new AnnouncerThread(address, dadereg, reply);
 
-							} catch (UnknownHostException uhe) {
+							} catch (final UnknownHostException uhe) {
 								throw new ServiceLocationException(
 										ServiceLocationException.NETWORK_ERROR,
 										uhe.getMessage());
-							} 
+							}
 						}
 					}
 					synchronized (registeredServices) {
@@ -386,13 +411,13 @@
 	 *             for various reasons like authentication failures etc.
 	 */
 	public AbstractSLPReplyMessage handleMessage(final AbstractSLPMessage msg)
-	throws ServiceLocationException {
-		short zero=0;
+			throws ServiceLocationException {
+		short zero = 0;
 		if (msg == null) {
 			return null;
 		}
 
-		String via = msg.isTcp() ? " (tcp)" : " (udp)";
+		final String via = msg.isTcp() ? " (tcp)" : " (udp)";
 
 		SLPCore.platform.logTraceMessage("RECEIVED (" + msg.getSource() + ":"
 				+ msg.getPort() + ") " + msg.toString() + via);
@@ -401,38 +426,51 @@
 
 		switch (msg.getFuncID()) {
 		case AbstractSLPMessage.SRVRQST:
-			if (msg.hasUnsupportedMandatoryExtensions()){
-				ServiceReplyMessage servreply = new ServiceReplyMessage();
+			if (msg.hasUnsupportedMandatoryExtensions()) {
+				final ServiceReplyMessage servreply = new ServiceReplyMessage();
 				servreply.setXid(msg.getXid());
 				servreply.setLocale(msg.getLocale());
-				servreply.setErrorCode(ServiceLocationException.OPTION_NOT_UNDERSTOOD);
+				servreply
+						.setErrorCode(ServiceLocationException.OPTION_NOT_UNDERSTOOD);
 				return servreply;
 			}
-			ServiceRequestMessage req = (ServiceRequestMessage) msg;
+			final ServiceRequestMessage req = (ServiceRequestMessage) msg;
 
-			List<ServiceURL> results = new ArrayList<ServiceURL>();
-			List<AbstractExtension> extensions = new ArrayList<AbstractExtension>();
-			for (int i=0;i<req.getScopes().length; i++) {
-				List<Service> services = registeredServices.get(req.getScopes()[i].toLowerCase());
+			final List<ServiceURL> results = new ArrayList<ServiceURL>();
+			final List<AbstractExtension> extensions = new ArrayList<AbstractExtension>();
+			for (int i = 0; i < req.getScopes().length; i++) {
+				final List<Service> services = registeredServices.get(req
+						.getScopes()[i].toLowerCase());
 				if (services == null) {
 					continue;
 				}
 
-				for (Service service : services) {
-					if (service.getURL().getServiceType().matches(req.getServiceType())) {
-						if (req.getPredicate() == null || req.getPredicate().equals("")) {
+				for (final Service service : services) {
+					if (service.getURL().getServiceType().matches(
+							req.getServiceType())) {
+						if (req.getPredicate() == null
+								|| req.getPredicate().equals("")) {
 							results.add(service.getURL());
-							if (req.hasExtensionType(AbstractExtension.ATTRIBUTE_LIST_EXTENSION)){
-								AttributeListExtension ale = new AttributeListExtension(service.getURL().toString(),SLPUtils.dictToString(service.getAttributesAsStringDict()));
+							if (req
+									.hasExtensionType(AbstractExtension.ATTRIBUTE_LIST_EXTENSION)) {
+								final AttributeListExtension ale = new AttributeListExtension(
+										service.getURL().toString(),
+										SLPUtils.dictToString(service
+												.getAttributesAsStringDict()));
 								extensions.add(ale);
 							}
 							continue;
 						}
-						Filter filter = SLPCore.platform.createFilter(req.getPredicate());
+						final Filter filter = SLPCore.platform.createFilter(req
+								.getPredicate());
 						if (filter.match(service.getAttributes())) {
 							results.add(service.getURL());
-							if (req.hasExtensionType(AbstractExtension.ATTRIBUTE_LIST_EXTENSION)){
-								AttributeListExtension ale = new AttributeListExtension(service.getURL().toString(),SLPUtils.dictToString(service.getAttributesAsStringDict()));
+							if (req
+									.hasExtensionType(AbstractExtension.ATTRIBUTE_LIST_EXTENSION)) {
+								final AttributeListExtension ale = new AttributeListExtension(
+										service.getURL().toString(),
+										SLPUtils.dictToString(service
+												.getAttributesAsStringDict()));
 								extensions.add(ale);
 							}
 						}
@@ -448,114 +486,117 @@
 			if (results.size() == 0 && req.isMulticast()) {
 				return null;
 			}
-			
+
 			reply = new ServiceReplyMessage();
-			ServiceReplyMessage servreply = (ServiceReplyMessage) reply;
+			final ServiceReplyMessage servreply = (ServiceReplyMessage) reply;
 			servreply.setXid(req.getXid());
 			servreply.setLocale(req.getLocale());
 			servreply.setErrorCode(zero);
-			servreply.setServiceURLs((ServiceURL[]) results.toArray(new ServiceURL[]{}));
-			
-			servreply.setExtensions(extensions.toArray(new AbstractExtension[]{}));
-			
+			servreply.setServiceURLs(results.toArray(new ServiceURL[] {}));
+
+			servreply.setExtensions(extensions
+					.toArray(new AbstractExtension[] {}));
+
 			if (SLPCore.CONFIG.getSecurityEnabled()) {
-				servreply.sign(SLPUtils.arrayToString(req.getSPIs(),","));
+				servreply.sign(SLPUtils.arrayToString(req.getSPIs(), ","));
 			}
 
 			return servreply;
 
 		case AbstractSLPMessage.ATTRRQST:
-			if (msg.hasUnsupportedMandatoryExtensions()){
-				AttributeReplyMessage attreply = new AttributeReplyMessage();
+			if (msg.hasUnsupportedMandatoryExtensions()) {
+				final AttributeReplyMessage attreply = new AttributeReplyMessage();
 				attreply.setXid(msg.getXid());
 				attreply.setLocale(msg.getLocale());
-				attreply.setErrorCode(ServiceLocationException.OPTION_NOT_UNDERSTOOD);
+				attreply
+						.setErrorCode(ServiceLocationException.OPTION_NOT_UNDERSTOOD);
 				return attreply;
 			}
-			
-			
-			AttributeRequestMessage attreq = (AttributeRequestMessage) msg;
+
+			final AttributeRequestMessage attreq = (AttributeRequestMessage) msg;
 
 			// moved this out of the for loop for performance
 			// the request can either be for a ServiceURL or a ServiceType
 			Object reqService;
 			boolean fullurl = false;
-			if ((attreq.getServiceUrl().getURL().indexOf("//") == -1) || (attreq.getServiceUrl().getHost().equals("nullnull"))) {
+			if (attreq.getServiceUrl().getURL().indexOf("//") == -1
+					|| attreq.getServiceUrl().getHost().equals("nullnull")) {
 				reqService = attreq.getServiceUrl().getServiceType();
 			} else {
 				fullurl = true;
 				reqService = new ServiceURL(attreq.getServiceUrl().getURL(), 0);
 			}
 
-			List<String> attResult = new ArrayList<String>();
-			for (int i=0;i<attreq.getScopes().length;i++) {
-				List<Service> services = registeredServices.get(attreq.getScopes()[i].toLowerCase());
+			final List<String> attResult = new ArrayList<String>();
+			for (int i = 0; i < attreq.getScopes().length; i++) {
+				final List<Service> services = registeredServices.get(attreq
+						.getScopes()[i].toLowerCase());
 				if (services == null) {
 					continue;
 				}
 
-
 				// if spi is sent, the request must be for a full url and
 				// the tag list has to be empty
-				if (attreq.getSPIs().length==0
-						|| (fullurl && attreq.getTags().length==0)) {
-					for (Service service:services) {
+				if (attreq.getSPIs().length == 0 || fullurl
+						&& attreq.getTags().length == 0) {
+					for (final Service service : services) {
 						if (service.getURL().matches(reqService)) {
-							attResult.addAll(SLPUtils.findMatches(
-									SLPUtils.arrayToList(attreq.getTags()), service.getAttributesAsStringDict()));
+							attResult.addAll(SLPUtils.findMatches(SLPUtils
+									.arrayToList(attreq.getTags()), service
+									.getAttributesAsStringDict()));
 						}
 					}
 				}
 			}
-			
+
 			String[] finalAtts = SLPUtils.listToStringArray(attResult);
-			if (!fullurl){
+			if (!fullurl) {
 				finalAtts = SLPUtils.mergeAttributes(attResult);
 			}
-				
+
 			reply = new AttributeReplyMessage();
-			AttributeReplyMessage attrep = (AttributeReplyMessage) reply;
+			final AttributeReplyMessage attrep = (AttributeReplyMessage) reply;
 			attrep.setAttributes(finalAtts);
 			attrep.setLocale(attreq.getLocale());
 			attrep.setXid(attreq.getXid());
 			attrep.setAuthBlocks(new AuthenticationBlock[0]);
 			attrep.setErrorCode(zero);
-			if (attreq.getSPIs().length>0 && !fullurl){
-				attrep.setErrorCode(ServiceLocationException.AUTHENTICATION_FAILED);
+			if (attreq.getSPIs().length > 0 && !fullurl) {
+				attrep
+						.setErrorCode(ServiceLocationException.AUTHENTICATION_FAILED);
 			}
 
-
-
 			if (SLPCore.CONFIG.getSecurityEnabled()) {
-				attrep.sign(SLPUtils.arrayToString(attreq.getSPIs(),","));
+				attrep.sign(SLPUtils.arrayToString(attreq.getSPIs(), ","));
 			}
 			return reply;
 		case AbstractSLPMessage.SRVTYPERQST:
-			
-			if (msg.hasUnsupportedMandatoryExtensions()){
-				ServiceTypeReplyMessage streply = new ServiceTypeReplyMessage();
+
+			if (msg.hasUnsupportedMandatoryExtensions()) {
+				final ServiceTypeReplyMessage streply = new ServiceTypeReplyMessage();
 				streply.setXid(msg.getXid());
 				streply.setLocale(msg.getLocale());
-				streply.setErrorCode(ServiceLocationException.OPTION_NOT_UNDERSTOOD);
+				streply
+						.setErrorCode(ServiceLocationException.OPTION_NOT_UNDERSTOOD);
 				return streply;
 			}
-			
-			ServiceTypeRequestMessage streq = (ServiceTypeRequestMessage) msg;
 
-			ArrayList<ServiceType> result = new ArrayList<ServiceType>();
+			final ServiceTypeRequestMessage streq = (ServiceTypeRequestMessage) msg;
+
+			final ArrayList<ServiceType> result = new ArrayList<ServiceType>();
 
 			// iterate over scopes
-			for (int i=0;i<streq.getScopes().length;i++) {
+			for (int i = 0; i < streq.getScopes().length; i++) {
 
 				// iterate over the registered services
-				List services = ((List) registeredServices
-						.get(streq.getScopes()[i]));
+				final List services = registeredServices
+						.get(streq.getScopes()[i]);
 				if (services == null) {
 					continue;
 				}
-				for (Iterator iter = services.iterator(); iter.hasNext();) {
-					Service service = (Service) iter.next();
-					ServiceType type = service.getURL().getServiceType();
+				for (final Iterator iter = services.iterator(); iter.hasNext();) {
+					final Service service = (Service) iter.next();
+					final ServiceType type = service.getURL().getServiceType();
 					if (streq.getNamingAuthority().equals("*")
 							|| streq.getNamingAuthority().equals("")
 							|| type.getNamingAuthority().equals(
@@ -568,29 +609,32 @@
 			}
 			zero = 0;
 			reply = new ServiceTypeReplyMessage();
-			ServiceTypeReplyMessage streply = (ServiceTypeReplyMessage) reply;
+			final ServiceTypeReplyMessage streply = (ServiceTypeReplyMessage) reply;
 			streply.setXid(streq.getXid());
 			streply.setLocale(streq.getLocale());
 			streply.setErrorCode(zero);
-			streply.setServiceTypes(ServiceTypeReplyMessage.listToServiceTypeArray(result));
+			streply.setServiceTypes(ServiceTypeReplyMessage
+					.listToServiceTypeArray(result));
 
 			return streply;
 
 		case AbstractSLPMessage.SRVREG:
-			
-			if (msg.hasUnsupportedMandatoryExtensions()){
-				ServiceAcknowledgementMessage ack = new ServiceAcknowledgementMessage();
+
+			if (msg.hasUnsupportedMandatoryExtensions()) {
+				final ServiceAcknowledgementMessage ack = new ServiceAcknowledgementMessage();
 				ack.setXid(msg.getXid());
 				ack.setLocale(msg.getLocale());
-				ack.setErrorCode(ServiceLocationException.OPTION_NOT_UNDERSTOOD);
+				ack
+						.setErrorCode(ServiceLocationException.OPTION_NOT_UNDERSTOOD);
 				return ack;
 			}
-			
-			
-			if (!((ServiceRegistrationMessage)msg).checkAttributeListValidity()){
-				ServiceAcknowledgementMessage srvreply = new ServiceAcknowledgementMessage();
+
+			if (!((ServiceRegistrationMessage) msg)
+					.checkAttributeListValidity()) {
+				final ServiceAcknowledgementMessage srvreply = new ServiceAcknowledgementMessage();
 				srvreply.setXid(msg.getXid());
-				srvreply.setErrorCode(ServiceLocationException.INVALID_REGISTRATION);
+				srvreply
+						.setErrorCode(ServiceLocationException.INVALID_REGISTRATION);
 				srvreply.setLocale(msg.getLocale());
 				srvreply.setSource(msg.getSource());
 				srvreply.setPort(msg.getPort());
@@ -603,10 +647,10 @@
 			srvreply.setLocale(msg.getLocale());
 			srvreply.setSource(msg.getSource());
 			srvreply.setPort(msg.getPort());
-			if (!((ServiceRegistrationMessage)msg).isFresh()){
+			if (!((ServiceRegistrationMessage) msg).isFresh()) {
 				try {
 					updateService((ServiceRegistrationMessage) msg);
-				} catch (ServiceLocationException sle){
+				} catch (final ServiceLocationException sle) {
 					srvreply.setErrorCode(sle.getErrorCode());
 				}
 			} else {
@@ -616,18 +660,19 @@
 			return srvreply;
 
 		case AbstractSLPMessage.SRVDEREG:
-			
-			if (msg.hasUnsupportedMandatoryExtensions()){
-				ServiceAcknowledgementMessage ack = new ServiceAcknowledgementMessage();
+
+			if (msg.hasUnsupportedMandatoryExtensions()) {
+				final ServiceAcknowledgementMessage ack = new ServiceAcknowledgementMessage();
 				ack.setXid(msg.getXid());
 				ack.setLocale(msg.getLocale());
-				ack.setErrorCode(ServiceLocationException.OPTION_NOT_UNDERSTOOD);
+				ack
+						.setErrorCode(ServiceLocationException.OPTION_NOT_UNDERSTOOD);
 				return ack;
 			}
-			
-			ServiceDeregistrationMessage dereg = (ServiceDeregistrationMessage) msg;
-//			check if tags have been set to delete attributes only...
-			if (dereg.getTags().length>0){
+
+			final ServiceDeregistrationMessage dereg = (ServiceDeregistrationMessage) msg;
+			// check if tags have been set to delete attributes only...
+			if (dereg.getTags().length > 0) {
 				deleteAttributes(dereg);
 			} else {
 				deregisterService(dereg);
@@ -641,7 +686,7 @@
 			return srvreply;
 
 		case AbstractSLPMessage.SRVACK:
-			if (msg.hasUnsupportedMandatoryExtensions()){
+			if (msg.hasUnsupportedMandatoryExtensions()) {
 				return null;
 			}
 			final AbstractSLPReplyMessage rep = (AbstractSLPReplyMessage) msg;
@@ -650,7 +695,8 @@
 						+ " replied with error code " + rep.getErrorCode()
 						+ " (" + rep + ")");
 			}
-			SLPCore.addReply(msg, new InetSocketAddress(msg.getSource(),msg.getPort()));
+			SLPCore.addReply(msg, new InetSocketAddress(msg.getSource(), msg
+					.getPort()));
 			return null;
 
 		default:
@@ -658,8 +704,9 @@
 			// exception during parsing
 			throw new ServiceLocationException(
 					ServiceLocationException.NOT_IMPLEMENTED,
-					"The message type " + AbstractSLPMessage.getType(msg.getFuncID())
-					+ " is not implemented");
+					"The message type "
+							+ AbstractSLPMessage.getType(msg.getFuncID())
+							+ " is not implemented");
 		}
 
 	}
@@ -673,76 +720,81 @@
 	 */
 	public void newDaDiscovered(final DAAdvertisementMessage advert) {
 		// so find all services within the scopes of the new DA:
-		for (int i=0;i<advert.getScopes().length;i++) {
-			String scope = advert.getScopes()[i].toLowerCase();
-			List services = (List) registeredServices.get(scope);
+		for (int i = 0; i < advert.getScopes().length; i++) {
+			final String scope = advert.getScopes()[i].toLowerCase();
+			final List services = registeredServices.get(scope);
 			if (services != null) {
-				for (Iterator serviceIter = services.iterator(); serviceIter
-				.hasNext();) {
+				for (final Iterator serviceIter = services.iterator(); serviceIter
+						.hasNext();) {
 					// and try to register it with the new DA
 					try {
-						Service service = (Service) serviceIter.next();
-						ServiceRegistrationMessage reg = new ServiceRegistrationMessage();
+						final Service service = (Service) serviceIter.next();
+						final ServiceRegistrationMessage reg = new ServiceRegistrationMessage();
 						reg.setServiceURL(service.getURL());
 						reg.setServiceType(service.getURL().getServiceType());
-						reg.setScopes(new String[]{scope});
-						reg.setAttrList(SLPUtils.listToStringArray(SLPUtils.dictToAttrList(service.getAttributes())));
+						reg.setScopes(new String[] { scope });
+						reg.setAttrList(SLPUtils.listToStringArray(SLPUtils
+								.dictToAttrList(service.getAttributes())));
 						reg.setLocale(SLPCore.DEFAULT_LOCALE);
 
 						SLPCore.platform.logDebug("Registering "
 								+ service.getURL() + " with new DA "
 								+ advert.getServiceURL());
-						// added by Lorenz to ensure adherence to RFC2608 section 12.2.1
-						long rand = Math.round(Math.random()*SLPCore.CONFIG.getConfigRegActive());
+						// added by Lorenz to ensure adherence to RFC2608
+						// section 12.2.1
+						final long rand = Math.round(Math.random()
+								* SLPCore.CONFIG.getConfigRegActive());
 						Thread.sleep(rand);
 
 						announceService(advert.getServiceURL().getHost(), reg);
-					} catch (ServiceLocationException e) {
+					} catch (final ServiceLocationException e) {
 						SLPCore.platform.logError(e.getMessage(), e
 								.fillInStackTrace());
-					} catch (InterruptedException ie){
+					} catch (final InterruptedException ie) {
 						// what has to happen here? announce again?
 					}
 				}
 			}
 		}
-		//update the timestamp:
-		SLPUtils.addValue(SLPCore.statelessBootTimestamps, advert.getServiceURL().getHost(), advert.getStatelessBootTimestamp());
+		// update the timestamp:
+		SLPUtils.addValue(SLPCore.statelessBootTimestamps, advert
+				.getServiceURL().getHost(), advert.getStatelessBootTimestamp());
 	}
 
 	/**
 	 * Provides direct access to the registered services.
 	 * 
-	 * @return
-	 * 		The cache of registered services
+	 * @return The cache of registered services
 	 */
-	public Map<String,List<Service>> getRegisteredServices(){
+	public Map<String, List<Service>> getRegisteredServices() {
 		return registeredServices;
 	}
 
-	
-
 	/**
 	 * Delete attributes from an existing regstration
 	 * 
 	 * @param dereg
-	 * 		The Deregistration Message asking for this to happen
+	 *            The Deregistration Message asking for this to happen
 	 * @throws ServiceLocationException
 	 */
-	private void deleteAttributes(ServiceDeregistrationMessage dereg) throws ServiceLocationException{
+	private void deleteAttributes(final ServiceDeregistrationMessage dereg)
+			throws ServiceLocationException {
 		// check for security has been done by the handler!
 		// message comes from the framework, considered safe for now...
 		Service registeredService = null;
 		boolean found = false;
-		for (int i=0;i<dereg.getScopes().length&&!found; i++) {
-			List<Service> services = registeredServices.get(dereg.getScopes()[i].toLowerCase().trim());
+		for (int i = 0; i < dereg.getScopes().length && !found; i++) {
+			final List<Service> services = registeredServices.get(dereg
+					.getScopes()[i].toLowerCase().trim());
 			if (services == null) {
 				continue;
 			}
 
-			for (Iterator<Service> srvs = services.iterator(); srvs.hasNext();) {
-				Service service = srvs.next();
-				if (service.getURL().toString().equals(dereg.getServiceURL().toString())){
+			for (final Iterator<Service> srvs = services.iterator(); srvs
+					.hasNext();) {
+				final Service service = srvs.next();
+				if (service.getURL().toString().equals(
+						dereg.getServiceURL().toString())) {
 					registeredService = service;
 					found = true;
 					break;
@@ -750,46 +802,55 @@
 			}
 		}
 
-		if (registeredService==null){
-			throw new ServiceLocationException(ServiceLocationException.INVALID_UPDATE,"No service to update...");
+		if (registeredService == null) {
+			throw new ServiceLocationException(
+					ServiceLocationException.INVALID_UPDATE,
+					"No service to update...");
 		}
 
-		Dictionary<String,Object> registeredAttributes = registeredService.getAttributes();
-		for (String t: dereg.getTags()){
+		final Dictionary<String, Object> registeredAttributes = registeredService
+				.getAttributes();
+		for (final String t : dereg.getTags()) {
 			registeredAttributes.remove(t);
 		}
 
 		// now propagate to DAs
 
-		final String[] scopes = (String[]) registeredServices.keySet().toArray(
+		final String[] scopes = registeredServices.keySet().toArray(
 				new String[registeredServices.size()]);
 		for (int i = 0; i < scopes.length; i++) {
-			final List<Service> tmp = registeredServices.get(scopes[i].toLowerCase());
-			final Service[] services = tmp.toArray(new Service[tmp
-			                                                   .size()]);
+			final List<Service> tmp = registeredServices.get(scopes[i]
+					.toLowerCase());
+			final Service[] services = tmp.toArray(new Service[tmp.size()]);
 
 			for (int j = 0; j < services.length; j++) {
 				if (dereg.getServiceURL().matches(services[j].getURL())) {
-					List<String> daList = SLPCore.dAs.get(scopes[i].toLowerCase());
+					final List<String> daList = SLPCore.dAs.get(scopes[i]
+							.toLowerCase());
 					if (daList != null) {
-						for (String dA : daList) {
+						for (final String dA : daList) {
 
-							// if there is a local DA in the same framework, delete the attribute directly from there
-							if (SLPUtils.arrayToList(SLPCore.myIPs).contains(dA)){
-								if (SLPCore.getDirectoryAgentDaemon()!=null){
-									SLPCore.getDirectoryAgentDaemon().deregisterService(dereg);
-								}  else {
-									// what? no daDaemon running?? must remove the ip from the list
-									SLPUtils.removeValueFromAll(SLPCore.dAs, dA);
+							// if there is a local DA in the same framework,
+							// delete the attribute directly from there
+							if (SLPUtils.arrayToList(SLPCore.myIPs)
+									.contains(dA)) {
+								if (SLPCore.getDirectoryAgentDaemon() != null) {
+									SLPCore.getDirectoryAgentDaemon()
+											.deregisterService(dereg);
+								} else {
+									// what? no daDaemon running?? must remove
+									// the ip from the list
+									SLPUtils
+											.removeValueFromAll(SLPCore.dAs, dA);
 									SLPCore.dASPIs.remove(dA);
 
 								}
 								return;
 							}
 
-//							deregister from all known remote DAs
+							// deregister from all known remote DAs
 
-							ServiceDeregistrationMessage dadereg = new ServiceDeregistrationMessage();
+							final ServiceDeregistrationMessage dadereg = new ServiceDeregistrationMessage();
 							dadereg.setLocale(dereg.getLocale());
 							dadereg.setMulticast(false);
 							dadereg.setScopes(dereg.getScopes());
@@ -797,35 +858,29 @@
 							dadereg.setTags(dereg.getTags());
 
 							try {
-								InetSocketAddress address = new InetSocketAddress(InetAddress.getByName(dA),SLPCore.SLP_PORT);
+								final InetSocketAddress address = new InetSocketAddress(
+										InetAddress.getByName(dA),
+										SLPCore.SLP_PORT);
 								dadereg.setXid(SLPCore.nextXid());
-								AbstractSLPReplyMessage reply = new ServiceReplyMessage();
-								new AnnouncerThread(address,dadereg,reply);
-							}  catch (UnknownHostException uhe) {
+								final AbstractSLPReplyMessage reply = new ServiceReplyMessage();
+								new AnnouncerThread(address, dadereg, reply);
+							} catch (final UnknownHostException uhe) {
 								throw new ServiceLocationException(
 										ServiceLocationException.NETWORK_ERROR,
 										uhe.getMessage());
-							} 
-
-
-
-
+							}
 
-						} 
+						}
 					}
 
-					// now that we have found a service that matches the one in dereg, we can move on to the next scope
+					// now that we have found a service that matches the one in
+					// dereg, we can move on to the next scope
 					break;
 				}
 			}
 		}
 	}
 
-
-
-
-
-
 	/**
 	 * register a service with a DA.
 	 * 
@@ -837,10 +892,12 @@
 	 *             in case of network errors.
 	 */
 	private void announceService(final String dAAddress,
-			final ServiceRegistrationMessage reg) throws ServiceLocationException {
+			final ServiceRegistrationMessage reg)
+			throws ServiceLocationException {
 		try {
-			InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(dAAddress),SLPCore.SLP_PORT);
-			ServiceRegistrationMessage dareg = new ServiceRegistrationMessage();
+			final InetSocketAddress addr = new InetSocketAddress(InetAddress
+					.getByName(dAAddress), SLPCore.SLP_PORT);
+			final ServiceRegistrationMessage dareg = new ServiceRegistrationMessage();
 			dareg.setAttrList(reg.getAttrList());
 			dareg.setAuthBlocks(reg.getAuthBlocks());
 			dareg.setLocale(reg.getLocale());
@@ -851,18 +908,17 @@
 			dareg.setXid(SLPCore.nextXid());
 			dareg.setFresh(reg.isFresh());
 			if (SLPCore.CONFIG.getSecurityEnabled()) {
-				List<String> spiList = SLPCore.dASPIs.get(dAAddress);
-				dareg.sign((String[]) spiList.toArray(new String[]{}));
+				final List<String> spiList = SLPCore.dASPIs.get(dAAddress);
+				dareg.sign(spiList.toArray(new String[] {}));
 			}
-			new AnnouncerThread(addr,dareg,null);
+			new AnnouncerThread(addr, dareg, null);
 
-		} catch (UnknownHostException e) {
-			SLPCore.platform.logError("Service announcement to "
-					+ dAAddress + " failed. ", e.fillInStackTrace());
+		} catch (final UnknownHostException e) {
+			SLPCore.platform.logError("Service announcement to " + dAAddress
+					+ " failed. ", e.fillInStackTrace());
 		}
 	}
 
-
 	/**
 	 * updatea service with a DA.
 	 * 
@@ -874,10 +930,12 @@
 	 *             in case of network errors.
 	 */
 	private void announceUpdatedService(final String dAAddress,
-			final ServiceRegistrationMessage reg, final Service service) throws ServiceLocationException {
+			final ServiceRegistrationMessage reg, final Service service)
+			throws ServiceLocationException {
 		try {
-			InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(dAAddress),SLPCore.SLP_PORT);
-			ServiceRegistrationMessage dareg = new ServiceRegistrationMessage();
+			final InetSocketAddress addr = new InetSocketAddress(InetAddress
+					.getByName(dAAddress), SLPCore.SLP_PORT);
+			final ServiceRegistrationMessage dareg = new ServiceRegistrationMessage();
 			dareg.setAttrList(reg.getAttrList());
 			dareg.setAuthBlocks(reg.getAuthBlocks());
 			dareg.setLocale(reg.getLocale());
@@ -888,23 +946,16 @@
 			dareg.setXid(SLPCore.nextXid());
 			dareg.setFresh(reg.isFresh());
 			if (SLPCore.CONFIG.getSecurityEnabled()) {
-				List<String> spiList = SLPCore.dASPIs.get(dAAddress);
-				dareg.sign((String[]) spiList.toArray(new String[]{}));
+				final List<String> spiList = SLPCore.dASPIs.get(dAAddress);
+				dareg.sign(spiList.toArray(new String[] {}));
 			}
-			new UpdaterThread(addr,dareg,service);
+			new UpdaterThread(addr, dareg, service);
 
-		} catch (UnknownHostException e) {
-			SLPCore.platform.logError("Service announcement to "
-					+ dAAddress + " failed. ", e.fillInStackTrace());
+		} catch (final UnknownHostException e) {
+			SLPCore.platform.logError("Service announcement to " + dAAddress
+					+ " failed. ", e.fillInStackTrace());
 		}
 	}
-	
-	
-
-	
-	
-	
-
 
 	/**
 	 * service disposal thread. Removes services from the local registry when
@@ -923,6 +974,7 @@
 		/**
 		 * thread's main loop.
 		 */
+		@Override
 		public void run() {
 			try {
 				while (running) {
@@ -930,33 +982,32 @@
 						if (serviceDisposalQueue.isEmpty()) {
 							// nothing to do, sleep until something arrives
 							SLPCore.platform
-							.logDebug("ServiceDisposalThread sleeping ...");
+									.logDebug("ServiceDisposalThread sleeping ...");
 							serviceDisposalQueue.wait();
 						} else {
 							// we have work, do everything that is due
 							Long nextActivity;
 							while (!serviceDisposalQueue.isEmpty()
-									&& (nextActivity = ((Long) serviceDisposalQueue
-											.firstKey())).longValue() <= System
+									&& (nextActivity = serviceDisposalQueue
+											.firstKey()).longValue() <= System
 											.currentTimeMillis()) {
 
-								ServiceURL service = (ServiceURL) serviceDisposalQueue
-								.get(nextActivity);
+								final ServiceURL service = serviceDisposalQueue
+										.get(nextActivity);
 
-								ServiceDeregistrationMessage dereg = new ServiceDeregistrationMessage();
+								final ServiceDeregistrationMessage dereg = new ServiceDeregistrationMessage();
 								dereg.setServiceURL(service);
 								dereg.setLocale(SLPCore.DEFAULT_LOCALE);
 
 								try {
 									deregisterService(dereg);
-								} catch (ServiceLocationException sle) {
-									SLPCore.platform.logError(sle
-											.getMessage(), sle
-											.fillInStackTrace());
+								} catch (final ServiceLocationException sle) {
+									SLPCore.platform.logError(sle.getMessage(),
+											sle.fillInStackTrace());
 								}
 								SLPCore.platform
-								.logTraceReg("disposed service "
-										+ service);
+										.logTraceReg("disposed service "
+												+ service);
 								serviceDisposalQueue.remove(nextActivity);
 							}
 							if (!serviceDisposalQueue.isEmpty()) {
@@ -964,44 +1015,40 @@
 								 * there are some activities in the future,
 								 * sleep until the first activity becomes due
 								 */
-								nextActivity = ((Long) serviceDisposalQueue
-										.firstKey());
-								long waitTime = nextActivity.longValue()
-								- System.currentTimeMillis();
+								nextActivity = serviceDisposalQueue.firstKey();
+								final long waitTime = nextActivity.longValue()
+										- System.currentTimeMillis();
 								if (waitTime > 0) {
-									SLPCore.platform
-									.logDebug("sleeping for "
-											+ waitTime / 1000
-											+ " seconds.");
+									SLPCore.platform.logDebug("sleeping for "
+											+ waitTime / 1000 + " seconds.");
 									serviceDisposalQueue.wait(waitTime);
 								}
 							}
 						}
 					}
 				}
-			} catch (InterruptedException ie) {
+			} catch (final InterruptedException ie) {
 				// let the thread stop.
 			}
 		}
 	}
 
-
-
 	/**
 	 * service anouncer thread.
 	 */
 	private final class AnnouncerThread extends Thread {
 
-
-		private InetSocketAddress addr;
-		private AbstractSLPMessage msg;
+		private final InetSocketAddress addr;
+		private final AbstractSLPMessage msg;
 		private AbstractSLPReplyMessage replyMsg;
 
-		private AnnouncerThread(InetSocketAddress sock,final AbstractSLPMessage message, AbstractSLPReplyMessage reply) {
-			addr=sock;
-			msg=message;
-			if (reply!=null){
-				replyMsg=reply;
+		private AnnouncerThread(final InetSocketAddress sock,
+				final AbstractSLPMessage message,
+				final AbstractSLPReplyMessage reply) {
+			addr = sock;
+			msg = message;
+			if (reply != null) {
+				replyMsg = reply;
 			} else {
 				replyMsg = new ServiceReplyMessage();
 			}
@@ -1011,96 +1058,114 @@
 		/**
 		 * thread's main loop.
 		 */
+		@Override
 		public void run() {
-			try{
-				AbstractSLPReplyMessage rm = SLPCore.sendReliableUnicastMessage(msg, addr, true);
-				if (rm!=null){
+			try {
+				final AbstractSLPReplyMessage rm = SLPCore
+						.sendReliableUnicastMessage(msg, addr, true);
+				if (rm != null) {
 					replyMsg.setErrorCode(rm.getErrorCode());
 				} else {
 
-					//remove DA from list
-					SLPUtils.removeValueFromAll(SLPCore.dAs, addr.getAddress().getHostAddress());
-					SLPCore.dASPIs.remove( addr.getAddress().getHostAddress());
+					// remove DA from list
+					SLPUtils.removeValueFromAll(SLPCore.dAs, addr.getAddress()
+							.getHostAddress());
+					SLPCore.dASPIs.remove(addr.getAddress().getHostAddress());
 				}
 
-				if (msg instanceof ServiceRegistrationMessage){
+				if (msg instanceof ServiceRegistrationMessage) {
 					SLPCore.platform.logTraceReg("ANNOUNCED "
-							+ ((ServiceRegistrationMessage)msg).getServiceURL() + " to " + addr.getAddress().getHostAddress());
-				} else if (msg instanceof ServiceDeregistrationMessage){
+							+ ((ServiceRegistrationMessage) msg)
+									.getServiceURL() + " to "
+							+ addr.getAddress().getHostAddress());
+				} else if (msg instanceof ServiceDeregistrationMessage) {
 					SLPCore.platform.logTraceReg("DEREGISTERED "
-							+ ((ServiceDeregistrationMessage)msg).getServiceURL() + " from " + addr.getAddress().getHostAddress());
-				} 
+							+ ((ServiceDeregistrationMessage) msg)
+									.getServiceURL() + " from "
+							+ addr.getAddress().getHostAddress());
+				}
 
-			} catch (ServiceLocationException sle){
-				if (msg instanceof ServiceRegistrationMessage){
+			} catch (final ServiceLocationException sle) {
+				if (msg instanceof ServiceRegistrationMessage) {
 					// remove DA from list
-					SLPUtils.removeValueFromAll(SLPCore.dAs, addr.getAddress().getHostAddress());
-					SLPCore.dASPIs.remove( addr.getAddress().getHostAddress());
-					SLPCore.platform.logError(sle.getMessage(), sle.fillInStackTrace());
-				} 
+					SLPUtils.removeValueFromAll(SLPCore.dAs, addr.getAddress()
+							.getHostAddress());
+					SLPCore.dASPIs.remove(addr.getAddress().getHostAddress());
+					SLPCore.platform.logError(sle.getMessage(), sle
+							.fillInStackTrace());
+				}
 			}
 		}
 	}
 
-
 	/**
 	 * service anouncer thread.
 	 */
 	private final class UpdaterThread extends Thread {
 
-
-		private InetSocketAddress addr;
-		private ServiceRegistrationMessage msg;
-		private Service srv;
-
-		private UpdaterThread(InetSocketAddress sock, ServiceRegistrationMessage message,final Service service) {
-			addr=sock;
-			msg=message;
-			srv=service;
+		private final InetSocketAddress addr;
+		private final ServiceRegistrationMessage msg;
+		private final Service srv;
+
+		private UpdaterThread(final InetSocketAddress sock,
+				final ServiceRegistrationMessage message, final Service service) {
+			addr = sock;
+			msg = message;
+			srv = service;
 			start();
 		}
 
 		/**
 		 * thread's main loop.
 		 */
+		@Override
 		public void run() {
-			try{
-				AbstractSLPReplyMessage rm = SLPCore.sendReliableUnicastMessage(msg, addr, true);
-				if (rm!=null){
-					if (rm.getErrorCode()!=0){
-						//DA may not udnerstand updates...
-						msg.setAttrList(SLPUtils.listToStringArray(SLPUtils.dictToAttrList(srv.getAttributes())));
+			try {
+				AbstractSLPReplyMessage rm = SLPCore
+						.sendReliableUnicastMessage(msg, addr, true);
+				if (rm != null) {
+					if (rm.getErrorCode() != 0) {
+						// DA may not udnerstand updates...
+						msg.setAttrList(SLPUtils.listToStringArray(SLPUtils
+								.dictToAttrList(srv.getAttributes())));
 						msg.setAuthBlocks(srv.getAuthBlocks());
 						msg.setXid(SLPCore.nextXid());
 						msg.setFresh(true);
 						if (SLPCore.CONFIG.getSecurityEnabled()) {
-							List<String> spiList = SLPCore.dASPIs.get(addr);
-							msg.sign((String[]) spiList.toArray(new String[]{}));
+							final List<String> spiList = SLPCore.dASPIs
+									.get(addr);
+							msg.sign(spiList.toArray(new String[] {}));
 						}
-						rm = SLPCore.sendReliableUnicastMessage(msg, addr, true);
-						if (rm==null){
-//							remove DA from list
-							SLPUtils.removeValueFromAll(SLPCore.dAs, addr.getAddress().getHostAddress());
-							SLPCore.dASPIs.remove( addr.getAddress().getHostAddress());
+						rm = SLPCore
+								.sendReliableUnicastMessage(msg, addr, true);
+						if (rm == null) {
+							// remove DA from list
+							SLPUtils.removeValueFromAll(SLPCore.dAs, addr
+									.getAddress().getHostAddress());
+							SLPCore.dASPIs.remove(addr.getAddress()
+									.getHostAddress());
 						}
 					}
 				} else {
 
-					//remove DA from list
-					SLPUtils.removeValueFromAll(SLPCore.dAs, addr.getAddress().getHostAddress());
-					SLPCore.dASPIs.remove( addr.getAddress().getHostAddress());
+					// remove DA from list
+					SLPUtils.removeValueFromAll(SLPCore.dAs, addr.getAddress()
+							.getHostAddress());
+					SLPCore.dASPIs.remove(addr.getAddress().getHostAddress());
 				}
 
 				SLPCore.platform.logTraceReg("ANNOUNCED "
-						+ ((ServiceRegistrationMessage)msg).getServiceURL() + " to " + addr.getAddress().getHostAddress());
-
+						+ (msg).getServiceURL() + " to "
+						+ addr.getAddress().getHostAddress());
 
-			} catch (ServiceLocationException sle){
+			} catch (final ServiceLocationException sle) {
 
 				// remove DA from list
-				SLPUtils.removeValueFromAll(SLPCore.dAs, addr.getAddress().getHostAddress());
-				SLPCore.dASPIs.remove( addr.getAddress().getHostAddress());
-				SLPCore.platform.logError(sle.getMessage(), sle.fillInStackTrace());
+				SLPUtils.removeValueFromAll(SLPCore.dAs, addr.getAddress()
+						.getHostAddress());
+				SLPCore.dASPIs.remove(addr.getAddress().getHostAddress());
+				SLPCore.platform.logError(sle.getMessage(), sle
+						.fillInStackTrace());
 
 			}
 		}

Modified: directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPHandler.java
URL: http://svn.apache.org/viewvc/directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPHandler.java?rev=782980&r1=782979&r2=782980&view=diff
==============================================================================
--- directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPHandler.java (original)
+++ directory/sandbox/slp/src/main/java/org/apache/directory/slp/impl/SLPHandler.java Tue Jun  9 12:50:45 2009
@@ -19,7 +19,6 @@
  */
 package org.apache.directory.slp.impl;
 
-
 import java.net.InetSocketAddress;
 
 import org.apache.directory.slp.ServiceLocationException;
@@ -34,399 +33,506 @@
 import org.apache.mina.core.session.IdleStatus;
 import org.apache.mina.core.session.IoSession;
 
-
 /**
- * The IoHandler processing incoming SLP messages and dispatching them to the correct agent for processing
+ * The IoHandler processing incoming SLP messages and dispatching them to the
+ * correct agent for processing
  * 
  * @author Lorenz Breu
- *
+ * 
  */
-public class SLPHandler extends IoHandlerAdapter{
-	
-	
-	public SLPHandler(){
+public class SLPHandler extends IoHandlerAdapter {
+
+	public SLPHandler() {
 
 	}
-	
+
 	@Override
-    public void exceptionCaught(IoSession session, Throwable cause)
-            throws Exception {
-        cause.printStackTrace();
-        session.close(false);
-    }
-
-    @Override
-    public void messageReceived(IoSession session, Object message) throws ServiceLocationException {
-    
-	if (message == null || !(message instanceof AbstractSLPMessage)) {
-		return;
+	public void exceptionCaught(final IoSession session, final Throwable cause)
+			throws Exception {
+		cause.printStackTrace();
+		session.close(false);
 	}
-	AbstractSLPMessage msg = (AbstractSLPMessage) message;
-	
-	
-	
-	InetSocketAddress address = (InetSocketAddress) session.getRemoteAddress();
-	SLPCore.platform.logDebug("RECEIVED (" + msg.getSource() + ":"
-			+ msg.getPort() + ") " + msg.toString());
-
-	switch (msg.getFuncID()) {
-	case AbstractSLPMessage.DAADVERT:
-		// drop message, if noDADiscovery is set
-		if (SLPCore.noDiscovery) {
-			if (SLPCore.discoveryException.equals(address.getAddress().getHostAddress())){
-				SLPCore.addReply(msg, address);
-			} else {
-				SLPCore.platform.logTraceDrop("DROPPED (" + address.getAddress() + ":"
-							+ address.getPort() + ") " + msg.toString()
-							+ "(reason: noDADiscovery is set");
-			}
-			session.close(false);
-			return;
-		}
 
-		DAAdvertisementMessage advert = (DAAdvertisementMessage) message;
+	@Override
+	public void messageReceived(final IoSession session, final Object message)
+			throws ServiceLocationException {
 
-		if (advert.getErrorCode() != 0) {
-			SLPCore.platform.logTraceDrop("DROPPED DAADvertisement (" + address.getAddress() + ":"
-					+ address.getPort() + ") " + advert.toString()
-					+ "(reason: " + advert.getErrorCode() + " != 0");
-			session.close(false);
+		if (message == null || !(message instanceof AbstractSLPMessage)) {
 			return;
 		}
-		// this should also prevent reverse-lookup each time a DA is contacted
-		if (advert.getServiceURL().getHost() != address.getAddress().getHostAddress()) {
-			advert.getServiceURL().setHost(address.getAddress().getHostAddress());
-		}
+		final AbstractSLPMessage msg = (AbstractSLPMessage) message;
 
-		// statelessBootTimestamp = 0 means DA is going down
-		if (advert.getStatelessBootTimestamp() == 0) {
-			for (int i=0;i<advert.getScopes().length;i++){
-				String scope = advert.getScopes()[i].toLowerCase().trim();
-				SLPUtils.removeValue(SLPCore.dAs,scope.toLowerCase(), advert.getServiceURL());
-			}
-		} else {
-			for (int i=0;i<advert.getScopes().length;i++){
-				String scope = advert.getScopes()[i].toLowerCase().trim();
-			
-				// If OpenSLP would strictly follow RFC 2608,
-				// it should only send a new statelessBootTimestamp
-				// if it was really rebooted or has lost
-				// registrations for other reasons.
-				// But it looks like OpenSLP sends a new sBT whenever
-				// it sends a DAADVERT so we will just reregister
-				// all of our services if we receive a new DAADVERT
-				// from OpenSLP.
-				
-				
-				SLPUtils.addValue(SLPCore.dAs, scope, advert.getServiceURL().getHost());
-				
-				if (SLPCore.CONFIG.getSecurityEnabled()) {
-					if (!advert.verify()){
-						session.close(false);
-						return;
-					}
-					SLPCore.dASPIs.put(advert.getServiceURL().getHost(), SLPUtils.arrayToList(
-							advert.getSPIs()));
+		final InetSocketAddress address = (InetSocketAddress) session
+				.getRemoteAddress();
+		SLPCore.platform.logDebug("RECEIVED (" + msg.getSource() + ":"
+				+ msg.getPort() + ") " + msg.toString());
+
+		switch (msg.getFuncID()) {
+		case AbstractSLPMessage.DAADVERT:
+			// drop message, if noDADiscovery is set
+			if (SLPCore.noDiscovery) {
+				if (SLPCore.discoveryException.equals(address.getAddress()
+						.getHostAddress())) {
+					SLPCore.addReply(msg, address);
+				} else {
+					SLPCore.platform.logTraceDrop("DROPPED ("
+							+ address.getAddress() + ":" + address.getPort()
+							+ ") " + msg.toString()
+							+ "(reason: noDADiscovery is set");
 				}
-
+				session.close(false);
+				return;
 			}
 
-			synchronized (SLPCore.dAs) {
-				SLPCore.dAs.notifyAll();
+			final DAAdvertisementMessage advert = (DAAdvertisementMessage) message;
+
+			if (advert.getErrorCode() != 0) {
+				SLPCore.platform.logTraceDrop("DROPPED DAADvertisement ("
+						+ address.getAddress() + ":" + address.getPort() + ") "
+						+ advert.toString() + "(reason: "
+						+ advert.getErrorCode() + " != 0");
+				session.close(false);
+				return;
+			}
+			// this should also prevent reverse-lookup each time a DA is
+			// contacted
+			if (advert.getServiceURL().getHost() != address.getAddress()
+					.getHostAddress()) {
+				advert.getServiceURL().setHost(
+						address.getAddress().getHostAddress());
 			}
 
-			// if there is a daemon instance, inform it about the discovered
-			// DA
-			if (SLPCore.getDaemon() != null) {
-				if (SLPCore.statelessBootTimestamps.get(advert.getServiceURL().getHost())==null){
-					SLPCore.getDaemon().newDaDiscovered(advert);
-				} else if (SLPCore.statelessBootTimestamps.get(advert.getServiceURL().getHost())<=advert.getStatelessBootTimestamp()){
-					SLPCore.getDaemon().newDaDiscovered(advert);
+			// statelessBootTimestamp = 0 means DA is going down
+			if (advert.getStatelessBootTimestamp() == 0) {
+				for (int i = 0; i < advert.getScopes().length; i++) {
+					final String scope = advert.getScopes()[i].toLowerCase()
+							.trim();
+					SLPUtils.removeValue(SLPCore.dAs, scope.toLowerCase(),
+							advert.getServiceURL());
 				}
-			}
+			} else {
+				for (int i = 0; i < advert.getScopes().length; i++) {
+					final String scope = advert.getScopes()[i].toLowerCase()
+							.trim();
+
+					// If OpenSLP would strictly follow RFC 2608,
+					// it should only send a new statelessBootTimestamp
+					// if it was really rebooted or has lost
+					// registrations for other reasons.
+					// But it looks like OpenSLP sends a new sBT whenever
+					// it sends a DAADVERT so we will just reregister
+					// all of our services if we receive a new DAADVERT
+					// from OpenSLP.
+
+					SLPUtils.addValue(SLPCore.dAs, scope, advert
+							.getServiceURL().getHost());
+
+					if (SLPCore.CONFIG.getSecurityEnabled()) {
+						if (!advert.verify()) {
+							session.close(false);
+							return;
+						}
+						SLPCore.dASPIs.put(advert.getServiceURL().getHost(),
+								SLPUtils.arrayToList(advert.getSPIs()));
+					}
 
-		}
-		SLPCore.platform.logDebug("NEW DA LIST: " + SLPCore.dAs);
-		SLPCore.addReply(advert, new InetSocketAddress(advert.getSource(),advert.getPort()));
-		session.close(false);
-		return;
+				}
+
+				synchronized (SLPCore.dAs) {
+					SLPCore.dAs.notifyAll();
+				}
+
+				// if there is a daemon instance, inform it about the discovered
+				// DA
+				if (SLPCore.getDaemon() != null) {
+					if (SLPCore.statelessBootTimestamps.get(advert
+							.getServiceURL().getHost()) == null) {
+						SLPCore.getDaemon().newDaDiscovered(advert);
+					} else if (SLPCore.statelessBootTimestamps.get(advert
+							.getServiceURL().getHost()) <= advert
+							.getStatelessBootTimestamp()) {
+						SLPCore.getDaemon().newDaDiscovered(advert);
+					}
+				}
 
-		// reply messages
-	case AbstractSLPMessage.ATTRRPLY:
-		if (msg.hasUnsupportedMandatoryExtensions()){
-			return;
-		}
-		//if the message comes from a different host and security is enabled, verify the message.
-		// if verification fails, drop the message and throw an exception
-		if (!msg.getSource().equals("127.0.0.1") && SLPCore.CONFIG.getSecurityEnabled()){
-			if (!((AttributeReplyMessage)msg).verify()){
-				throw new ServiceLocationException(ServiceLocationException.AUTHENTICATION_FAILED,"Failed to verify AttributeReply");
-			}
-		}
-		SLPCore.addReply(msg, address);
-		session.close(false);
-		return;
-	case AbstractSLPMessage.SRVRPLY:
-		if (msg.hasUnsupportedMandatoryExtensions()){
-			return;
-		}
-		// if the message comes from a different host and security is enabled, verify the message.
-		// if verification fails, drop the message and throw an exception
-		if (!msg.getSource().equals("127.0.0.1") && SLPCore.CONFIG.getSecurityEnabled()){
-			if (!((ServiceReplyMessage)msg).verify()){
-				throw new ServiceLocationException(ServiceLocationException.AUTHENTICATION_FAILED,"Failed to verify ServiceReply");
 			}
-		}
-		SLPCore.addReply(msg, address);
-		session.close(false);
-		return;
-	case AbstractSLPMessage.SRVTYPERPLY:
-		if (msg.hasUnsupportedMandatoryExtensions()){
+			SLPCore.platform.logDebug("NEW DA LIST: " + SLPCore.dAs);
+			SLPCore.addReply(advert, new InetSocketAddress(advert.getSource(),
+					advert.getPort()));
+			session.close(false);
 			return;
-		}
-		// add the reply to the queue if it has been verified...
-		SLPCore.addReply(msg, address);
-		session.close(false);
-		return;
-		// request messages
-	case AbstractSLPMessage.SRVRQST:
-	case AbstractSLPMessage.ATTRRQST:
-	case AbstractSLPMessage.SRVTYPERQST:
-		// silently drop messages where this peer is in the previous
-		// responder list
-		for (int i = 0; i < SLPCore.myIPs.length; i++) {
-			if (((AbstractSLPRequestMessage) message).knowsResponder(SLPCore.myIPs[i])) {
-				SLPCore.platform.logTraceDrop("DROPPED (" + address.getAddress() + ":"
-							+ address.getPort() + ") " + msg.toString()
-							+ "(udp multicast)");
-				session.close(false);
+
+			// reply messages
+		case AbstractSLPMessage.ATTRRPLY:
+			if (msg.hasUnsupportedMandatoryExtensions()) {
 				return;
 			}
-		}
-		
-		// if a DA is running, all requests should be passed to it
-		if (SLPCore.getDirectoryAgentDaemon() != null) {
-			AbstractSLPMessage reply = SLPCore.getDirectoryAgentDaemon().handleMessage(msg);
-			if (reply!=null){
-				if (msg.isMulticast()){
-					SLPCore.sendUnicastMessage(reply, new InetSocketAddress(msg.getSource(),msg.getPort()), false);
-				} else {
-					if (reply.getSize()>SLPCore.CONFIG.getMTU()){
-						SLPCore.sendMessageTCP(reply, new InetSocketAddress(msg.getSource(),SLPCore.SLP_PORT), false);
-						session.close(false);
-						return;
-					}
-					session.write(reply);
-					SLPCore.platform.logTraceMessage("SENT (" + msg.getSource() + ":" + msg.getPort() + ") "
-							+ reply + " (via udp port " +((InetSocketAddress) session.getLocalAddress()).getPort()
-							+ ")");
+			// if the message comes from a different host and security is
+			// enabled, verify the message.
+			// if verification fails, drop the message and throw an exception
+			if (!msg.getSource().equals("127.0.0.1")
+					&& SLPCore.CONFIG.getSecurityEnabled()) {
+				if (!((AttributeReplyMessage) msg).verify()) {
+					throw new ServiceLocationException(
+							ServiceLocationException.AUTHENTICATION_FAILED,
+							"Failed to verify AttributeReply");
 				}
 			}
+			SLPCore.addReply(msg, address);
 			session.close(false);
 			return;
-		} 
-		
-
-		// else if we have a daemon instance, delegate the
-		// message to the daemon.
-		if (SLPCore.getDaemon() != null) {
-			AbstractSLPMessage reply = SLPCore.getDaemon().handleMessage(msg);
-			if (reply!=null){
-				if (msg.isMulticast()){
-					SLPCore.sendUnicastMessage(reply, new InetSocketAddress(msg.getSource(),msg.getPort()), false);
-				} else {
-					if (reply.getSize()>SLPCore.CONFIG.getMTU()){
-						SLPCore.sendMessageTCP(reply, new InetSocketAddress(msg.getSource(),SLPCore.SLP_PORT), false);
-						session.close(false);
-						return;
-					}
-					session.write(reply);
-					SLPCore.platform.logTraceMessage("SENT (" + msg.getSource() + ":" + msg.getPort() + ") "
-							+ reply + " (via udp port " +((InetSocketAddress) session.getLocalAddress()).getPort()
-							+ ")");
+		case AbstractSLPMessage.SRVRPLY:
+			if (msg.hasUnsupportedMandatoryExtensions()) {
+				return;
+			}
+			// if the message comes from a different host and security is
+			// enabled, verify the message.
+			// if verification fails, drop the message and throw an exception
+			if (!msg.getSource().equals("127.0.0.1")
+					&& SLPCore.CONFIG.getSecurityEnabled()) {
+				if (!((ServiceReplyMessage) msg).verify()) {
+					throw new ServiceLocationException(
+							ServiceLocationException.AUTHENTICATION_FAILED,
+							"Failed to verify ServiceReply");
 				}
 			}
-			
+			SLPCore.addReply(msg, address);
 			session.close(false);
 			return;
-		} else {
-			SLPCore.platform.logDebug("Request recieved ("
-					+ address.getAddress().getHostAddress() + ":" + address.getPort() + ") "
-					+ msg.toString()
-					+ " but no SLPDaemon to handle the message present");
+		case AbstractSLPMessage.SRVTYPERPLY:
+			if (msg.hasUnsupportedMandatoryExtensions()) {
+				return;
+			}
+			// add the reply to the queue if it has been verified...
+			SLPCore.addReply(msg, address);
 			session.close(false);
 			return;
-		}
-	
-	case AbstractSLPMessage.SRVREG:
-		
-		if (SLPCore.CONFIG.getSecurityEnabled()){
-			if (!((ServiceRegistrationMessage)msg).verify()){
-				ServiceAcknowledgementMessage ack = new ServiceAcknowledgementMessage();
-				ack.setXid(msg.getXid());
-				ack.setErrorCode(ServiceLocationException.AUTHENTICATION_FAILED);
-				if (msg.isMulticast()){
-					SLPCore.sendUnicastMessage(ack, new InetSocketAddress(msg.getSource(),msg.getPort()), false);
-				} else {
-					session.write(ack);
-					SLPCore.platform.logTraceMessage("SENT (" + msg.getSource() + ":" + msg.getPort() + ") "
-							+ ack + " (via udp port " +((InetSocketAddress) session.getLocalAddress()).getPort()
-							+ ")");
+			// request messages
+		case AbstractSLPMessage.SRVRQST:
+		case AbstractSLPMessage.ATTRRQST:
+		case AbstractSLPMessage.SRVTYPERQST:
+			// silently drop messages where this peer is in the previous
+			// responder list
+			for (int i = 0; i < SLPCore.myIPs.length; i++) {
+				if (((AbstractSLPRequestMessage) message)
+						.knowsResponder(SLPCore.myIPs[i])) {
+					SLPCore.platform.logTraceDrop("DROPPED ("
+							+ address.getAddress() + ":" + address.getPort()
+							+ ") " + msg.toString() + "(udp multicast)");
+					session.close(false);
+					return;
 				}
 			}
-		}
-		
-		// if the reg comes from within the framework, pass it to the SA part...
-		if (SLPUtils.arrayToList(SLPCore.myIPs).contains(msg.getSource())){
-			if (SLPCore.getDaemon()!=null){
-				AbstractSLPMessage reply = SLPCore.getDaemon().handleMessage(msg);
-				if (reply!=null){
-					if (msg.isMulticast()){
-						SLPCore.sendUnicastMessage(reply, new InetSocketAddress(msg.getSource(),msg.getPort()), false);
+
+			// if a DA is running, all requests should be passed to it
+			if (SLPCore.getDirectoryAgentDaemon() != null) {
+				final AbstractSLPMessage reply = SLPCore
+						.getDirectoryAgentDaemon().handleMessage(msg);
+				if (reply != null) {
+					if (msg.isMulticast()) {
+						SLPCore.sendUnicastMessage(reply,
+								new InetSocketAddress(msg.getSource(), msg
+										.getPort()), false);
 					} else {
+						if (reply.getSize() > SLPCore.CONFIG.getMTU()) {
+							SLPCore.sendMessageTCP(reply,
+									new InetSocketAddress(msg.getSource(),
+											SLPCore.SLP_PORT), false);
+							session.close(false);
+							return;
+						}
 						session.write(reply);
-						SLPCore.platform.logTraceMessage("SENT (" + msg.getSource() + ":" + msg.getPort() + ") "
-								+ reply + " (via udp port " +((InetSocketAddress) session.getLocalAddress()).getPort()
-								+ ")");
+						SLPCore.platform.logTraceMessage("SENT ("
+								+ msg.getSource()
+								+ ":"
+								+ msg.getPort()
+								+ ") "
+								+ reply
+								+ " (via udp port "
+								+ ((InetSocketAddress) session
+										.getLocalAddress()).getPort() + ")");
 					}
 				}
 				session.close(false);
 				return;
 			}
-		}
-		// this reg comes from outside
-		if (SLPCore.getDirectoryAgentDaemon() != null) {
-			AbstractSLPMessage reply = SLPCore.getDirectoryAgentDaemon().handleMessage(msg);
-			if (reply!=null){
-				if (msg.isMulticast()){
-					SLPCore.sendUnicastMessage(reply, new InetSocketAddress(msg.getSource(),msg.getPort()), false);
-				} else {
-					session.write(reply);
-					SLPCore.platform.logTraceMessage("SENT (" + msg.getSource() + ":" + msg.getPort() + ") "
-							+ reply + " (via udp port " +((InetSocketAddress) session.getLocalAddress()).getPort()
-							+ ")");
+
+			// else if we have a daemon instance, delegate the
+			// message to the daemon.
+			if (SLPCore.getDaemon() != null) {
+				final AbstractSLPMessage reply = SLPCore.getDaemon()
+						.handleMessage(msg);
+				if (reply != null) {
+					if (msg.isMulticast()) {
+						SLPCore.sendUnicastMessage(reply,
+								new InetSocketAddress(msg.getSource(), msg
+										.getPort()), false);
+					} else {
+						if (reply.getSize() > SLPCore.CONFIG.getMTU()) {
+							SLPCore.sendMessageTCP(reply,
+									new InetSocketAddress(msg.getSource(),
+											SLPCore.SLP_PORT), false);
+							session.close(false);
+							return;
+						}
+						session.write(reply);
+						SLPCore.platform.logTraceMessage("SENT ("
+								+ msg.getSource()
+								+ ":"
+								+ msg.getPort()
+								+ ") "
+								+ reply
+								+ " (via udp port "
+								+ ((InetSocketAddress) session
+										.getLocalAddress()).getPort() + ")");
+					}
 				}
+
+				session.close(false);
+				return;
+			} else {
+				SLPCore.platform.logDebug("Request recieved ("
+						+ address.getAddress().getHostAddress() + ":"
+						+ address.getPort() + ") " + msg.toString()
+						+ " but no SLPDaemon to handle the message present");
+				session.close(false);
+				return;
 			}
-			session.close(false);
-			return;
-		}
-		
-	case AbstractSLPMessage.SRVDEREG:
-		// if the reg comes from within the framework, pass it to the SA part...
-		if (SLPUtils.arrayToList(SLPCore.myIPs).contains(msg.getSource())){
-			if (SLPCore.getDaemon()!=null){
-				AbstractSLPMessage reply = SLPCore.getDaemon().handleMessage(msg);
-				if (reply!=null){
-					if (msg.isMulticast()){
-						SLPCore.sendUnicastMessage(reply, new InetSocketAddress(msg.getSource(),msg.getPort()), false);
+
+		case AbstractSLPMessage.SRVREG:
+
+			if (SLPCore.CONFIG.getSecurityEnabled()) {
+				if (!((ServiceRegistrationMessage) msg).verify()) {
+					final ServiceAcknowledgementMessage ack = new ServiceAcknowledgementMessage();
+					ack.setXid(msg.getXid());
+					ack
+							.setErrorCode(ServiceLocationException.AUTHENTICATION_FAILED);
+					if (msg.isMulticast()) {
+						SLPCore.sendUnicastMessage(ack, new InetSocketAddress(
+								msg.getSource(), msg.getPort()), false);
+					} else {
+						session.write(ack);
+						SLPCore.platform.logTraceMessage("SENT ("
+								+ msg.getSource()
+								+ ":"
+								+ msg.getPort()
+								+ ") "
+								+ ack
+								+ " (via udp port "
+								+ ((InetSocketAddress) session
+										.getLocalAddress()).getPort() + ")");
+					}
+				}
+			}
+
+			// if the reg comes from within the framework, pass it to the SA
+			// part...
+			if (SLPUtils.arrayToList(SLPCore.myIPs).contains(msg.getSource())) {
+				if (SLPCore.getDaemon() != null) {
+					final AbstractSLPMessage reply = SLPCore.getDaemon()
+							.handleMessage(msg);
+					if (reply != null) {
+						if (msg.isMulticast()) {
+							SLPCore.sendUnicastMessage(reply,
+									new InetSocketAddress(msg.getSource(), msg
+											.getPort()), false);
+						} else {
+							session.write(reply);
+							SLPCore.platform
+									.logTraceMessage("SENT ("
+											+ msg.getSource()
+											+ ":"
+											+ msg.getPort()
+											+ ") "
+											+ reply
+											+ " (via udp port "
+											+ ((InetSocketAddress) session
+													.getLocalAddress())
+													.getPort() + ")");
+						}
+					}
+					session.close(false);
+					return;
+				}
+			}
+			// this reg comes from outside
+			if (SLPCore.getDirectoryAgentDaemon() != null) {
+				final AbstractSLPMessage reply = SLPCore
+						.getDirectoryAgentDaemon().handleMessage(msg);
+				if (reply != null) {
+					if (msg.isMulticast()) {
+						SLPCore.sendUnicastMessage(reply,
+								new InetSocketAddress(msg.getSource(), msg
+										.getPort()), false);
 					} else {
 						session.write(reply);
-						SLPCore.platform.logTraceMessage("SENT (" + msg.getSource() + ":" + msg.getPort() + ") "
-								+ reply + " (via udp port " +((InetSocketAddress) session.getLocalAddress()).getPort()
-								+ ")");
+						SLPCore.platform.logTraceMessage("SENT ("
+								+ msg.getSource()
+								+ ":"
+								+ msg.getPort()
+								+ ") "
+								+ reply
+								+ " (via udp port "
+								+ ((InetSocketAddress) session
+										.getLocalAddress()).getPort() + ")");
 					}
 				}
 				session.close(false);
 				return;
 			}
-		}
-		// this reg comes from outside
-		if (SLPCore.getDirectoryAgentDaemon() != null) {
-			AbstractSLPMessage reply = SLPCore.getDirectoryAgentDaemon().handleMessage(msg);
-			if (reply!=null){
-				if (msg.isMulticast()){
-					SLPCore.sendUnicastMessage(reply, new InetSocketAddress(msg.getSource(),msg.getPort()), false);
-				} else {
-					session.write(reply);
-					SLPCore.platform.logTraceMessage("SENT (" + msg.getSource() + ":" + msg.getPort() + ") "
-							+ reply + " (via udp port " +((InetSocketAddress) session.getLocalAddress()).getPort()
-							+ ")");
+
+		case AbstractSLPMessage.SRVDEREG:
+			// if the reg comes from within the framework, pass it to the SA
+			// part...
+			if (SLPUtils.arrayToList(SLPCore.myIPs).contains(msg.getSource())) {
+				if (SLPCore.getDaemon() != null) {
+					final AbstractSLPMessage reply = SLPCore.getDaemon()
+							.handleMessage(msg);
+					if (reply != null) {
+						if (msg.isMulticast()) {
+							SLPCore.sendUnicastMessage(reply,
+									new InetSocketAddress(msg.getSource(), msg
+											.getPort()), false);
+						} else {
+							session.write(reply);
+							SLPCore.platform
+									.logTraceMessage("SENT ("
+											+ msg.getSource()
+											+ ":"
+											+ msg.getPort()
+											+ ") "
+											+ reply
+											+ " (via udp port "
+											+ ((InetSocketAddress) session
+													.getLocalAddress())
+													.getPort() + ")");
+						}
+					}
+					session.close(false);
+					return;
 				}
 			}
-			session.close(false);
-			return;
-		}
-		
-	case AbstractSLPMessage.SRVACK:
-		if (msg.hasUnsupportedMandatoryExtensions()){
-			return;
-		}
-		
-		SLPCore.addReply(msg, new InetSocketAddress(msg.getSource(),msg.getPort()));
-		return;	
-		
-		
-	default:
-		// if we have a DA running, pass messages (in this case reg and dereg) to it.
-		// the da will relegate reg and deregs coming from the framework on to the SA if present
-		if (SLPCore.getDirectoryAgentDaemon() != null) {
-			AbstractSLPMessage reply = SLPCore.getDirectoryAgentDaemon().handleMessage(msg);
-			if (reply!=null){
-				if (msg.isMulticast()){
-					SLPCore.sendUnicastMessage(reply, new InetSocketAddress(msg.getSource(),msg.getPort()), false);
-				} else {
-					session.write(reply);
-					SLPCore.platform.logTraceMessage("SENT (" + msg.getSource() + ":" + msg.getPort() + ") "
-							+ reply + " (via udp port " +((InetSocketAddress) session.getLocalAddress()).getPort()
-							+ ")");
+			// this reg comes from outside
+			if (SLPCore.getDirectoryAgentDaemon() != null) {
+				final AbstractSLPMessage reply = SLPCore
+						.getDirectoryAgentDaemon().handleMessage(msg);
+				if (reply != null) {
+					if (msg.isMulticast()) {
+						SLPCore.sendUnicastMessage(reply,
+								new InetSocketAddress(msg.getSource(), msg
+										.getPort()), false);
+					} else {
+						session.write(reply);
+						SLPCore.platform.logTraceMessage("SENT ("
+								+ msg.getSource()
+								+ ":"
+								+ msg.getPort()
+								+ ") "
+								+ reply
+								+ " (via udp port "
+								+ ((InetSocketAddress) session
+										.getLocalAddress()).getPort() + ")");
+					}
 				}
+				session.close(false);
+				return;
 			}
-			session.close(false);
+
+		case AbstractSLPMessage.SRVACK:
+			if (msg.hasUnsupportedMandatoryExtensions()) {
+				return;
+			}
+
+			SLPCore.addReply(msg, new InetSocketAddress(msg.getSource(), msg
+					.getPort()));
 			return;
-		} 
-		
-		
-		// if we have a daemon instance but no DA, delegate all other
-		// messages to the daemon.
-		if (SLPCore.getDaemon() != null) {
-			AbstractSLPMessage reply = SLPCore.getDaemon().handleMessage(msg);
-			if (reply!=null){
-				if (msg.isMulticast()){
-					SLPCore.sendUnicastMessage(reply, new InetSocketAddress(msg.getSource(),msg.getPort()), false);
-				} else {
-					session.write(reply);
-					SLPCore.platform.logTraceMessage("SENT (" + msg.getSource() + ":" + msg.getPort() + ") "
-							+ reply + " (via udp port " +((InetSocketAddress) session.getLocalAddress()).getPort()
-							+ ")");
+
+		default:
+			// if we have a DA running, pass messages (in this case reg and
+			// dereg) to it.
+			// the da will relegate reg and deregs coming from the framework on
+			// to the SA if present
+			if (SLPCore.getDirectoryAgentDaemon() != null) {
+				final AbstractSLPMessage reply = SLPCore
+						.getDirectoryAgentDaemon().handleMessage(msg);
+				if (reply != null) {
+					if (msg.isMulticast()) {
+						SLPCore.sendUnicastMessage(reply,
+								new InetSocketAddress(msg.getSource(), msg
+										.getPort()), false);
+					} else {
+						session.write(reply);
+						SLPCore.platform.logTraceMessage("SENT ("
+								+ msg.getSource()
+								+ ":"
+								+ msg.getPort()
+								+ ") "
+								+ reply
+								+ " (via udp port "
+								+ ((InetSocketAddress) session
+										.getLocalAddress()).getPort() + ")");
+					}
 				}
+				session.close(false);
+				return;
+			}
+
+			// if we have a daemon instance but no DA, delegate all other
+			// messages to the daemon.
+			if (SLPCore.getDaemon() != null) {
+				final AbstractSLPMessage reply = SLPCore.getDaemon()
+						.handleMessage(msg);
+				if (reply != null) {
+					if (msg.isMulticast()) {
+						SLPCore.sendUnicastMessage(reply,
+								new InetSocketAddress(msg.getSource(), msg
+										.getPort()), false);
+					} else {
+						session.write(reply);
+						SLPCore.platform.logTraceMessage("SENT ("
+								+ msg.getSource()
+								+ ":"
+								+ msg.getPort()
+								+ ") "
+								+ reply
+								+ " (via udp port "
+								+ ((InetSocketAddress) session
+										.getLocalAddress()).getPort() + ")");
+					}
+				}
+
+				session.close(false);
+				return;
+			} else {
+				SLPCore.platform.logDebug("A message recieved ("
+						+ address.getAddress() + ":" + address.getPort() + ") "
+						+ msg.toString()
+						+ " but no SLPDaemon to handle the message present");
+				session.close(false);
+				return;
 			}
-			
-			session.close(false);
-			return;
-		} else {
-			SLPCore.platform.logDebug("A message recieved ("
-					+ address.getAddress() + ":" + address.getPort() + ") "
-					+ msg.toString()
-					+ " but no SLPDaemon to handle the message present");
-			session.close(false);
-			return;
 		}
+
 	}
 
-}
+	@Override
+	public void sessionClosed(final IoSession session) throws Exception {
 
-    @Override
-    public void sessionClosed(IoSession session) throws Exception {
-        
-    }
-
-    @Override
-    public void sessionCreated(IoSession session) throws Exception {
-
-        
-    }
-
-    @Override
-    public void sessionIdle(IoSession session, IdleStatus status)
-            throws Exception {
-        
-    }
-
-    @Override
-    public void sessionOpened(IoSession session) throws Exception {
-        
-    }
-}
+	}
+
+	@Override
+	public void sessionCreated(final IoSession session) throws Exception {
 
+	}
 
+	@Override
+	public void sessionIdle(final IoSession session, final IdleStatus status)
+			throws Exception {
+
+	}
 
+	@Override
+	public void sessionOpened(final IoSession session) throws Exception {
+
+	}
+}



Mime
View raw message