From: <bd...@us...> - 2007-05-23 07:58:11
|
Revision: 861 http://svn.sourceforge.net/unicore/?rev=861&view=rev Author: bdemuth Date: 2007-05-23 00:58:10 -0700 (Wed, 23 May 2007) Log Message: ----------- Revised expiry checking Modified Paths: -------------- unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/LocalRegistryEntryHomeImpl.java unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/LocalRegistryImpl.java unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/RegistryEntryImpl.java unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/RegistryEntryUpdater.java unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/RegistryHandler.java wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/impl/DefaultHome.java wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/impl/ExpiryChecker.java wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/impl/InstanceChecker.java wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/impl/WSResourceImpl.java wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/sg/impl/ServiceGroupRegistrationImpl.java wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/wsn/impl/NotificationProducerHomeImpl.java wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/wsn/impl/WSNEventChecker.java wsrflite/wsrfcore/trunk/src/test/java/de/fzj/unicore/wsrflite/functional/TestWSResourceHomeImpl.java wsrflite/wsrfcore/trunk/src/test/java/de/fzj/unicore/wsrflite/impl/TestExpireWSResources.java Added Paths: ----------- wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/impl/InstanceChecking.java Modified: unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/LocalRegistryEntryHomeImpl.java =================================================================== --- unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/LocalRegistryEntryHomeImpl.java 2007-05-23 07:32:18 UTC (rev 860) +++ unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/LocalRegistryEntryHomeImpl.java 2007-05-23 07:58:10 UTC (rev 861) @@ -38,6 +38,8 @@ import de.fzj.unicore.uas.impl.UASWSResourceHomeImpl; import de.fzj.unicore.wsrflite.Kernel; +import de.fzj.unicore.wsrflite.impl.ExpiryChecker; +import de.fzj.unicore.wsrflite.impl.InstanceChecking; import de.fzj.unicore.wsrflite.xmlbeans.impl.WSResourceImpl; public class LocalRegistryEntryHomeImpl extends UASWSResourceHomeImpl { @@ -46,28 +48,14 @@ /** * setup the expiry check - * this implementation can be customised by - * setting two parameters: - * @see EXPIRYCHECK_INITIAL - * @see EXPIRYCHECK_PERIOD + * Local registry entries do not expire but become refreshed when they reach + * their termination time. */ protected void initExpiryCheck(){ - expiryChecker = new RegistryEntryUpdater(this,serviceInstances.getUniqueIDs()); - reaper = Executors.newScheduledThreadPool(1); - int initial; - int period; - try{ - initial=Integer.parseInt(Kernel.getKernel().getProperty(EXPIRYCHECK_INITIAL)); - }catch(Exception e){ - initial=1; - } - try{ - period=Integer.parseInt(Kernel.getKernel().getProperty(EXPIRYCHECK_PERIOD)); - }catch(Exception e){ - period=3; - } - logger.info("Expiry thread scheduled at a period of "+period+" secs."); - reaper.scheduleAtFixedRate(expiryChecker,period,initial,TimeUnit.SECONDS); + super.initExpiryCheck(); + instanceChecking.removeChecker(expiryChecker); + expiryChecker = new RegistryEntryUpdater(); + instanceChecking.addChecker(expiryChecker); } Modified: unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/LocalRegistryImpl.java =================================================================== --- unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/LocalRegistryImpl.java 2007-05-23 07:32:18 UTC (rev 860) +++ unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/LocalRegistryImpl.java 2007-05-23 07:58:10 UTC (rev 861) @@ -34,6 +34,7 @@ import java.util.Calendar; import java.util.logging.Level; +import java.util.logging.Logger; import org.oasisOpen.docs.wsrf.sg2.AddDocument; import org.oasisOpen.docs.wsrf.sg2.AddResponseDocument; @@ -56,8 +57,8 @@ */ private static final long serialVersionUID = 2905144125083560142L; protected static final long readd_offset = 60000; + protected static Logger logger=Logger.getLogger(LocalRegistryImpl.class.getName()); - /** * add a service to this service group. * this will create a new ws resource to represent the entry. @@ -69,14 +70,16 @@ if(external_registry_url != null) { // notify external registry and ask it for termination time for entry EndpointReferenceType external_registry_epr = RegistryHandler.getExternalRegistryEpr(); - try { + logger.fine("Trying to add entry to external registry."); RegistryClient external_registry_client = new RegistryClient(external_registry_url,external_registry_epr,UAS.getSecurityProperties()); Calendar external_registry_time = external_registry_client.getCurrentTime(); AddResponseDocument external_res = external_registry_client.addRegistryEntry(in); long time_difference = System.currentTimeMillis() - external_registry_time.getTimeInMillis(); termination_time = Calendar.getInstance(); - termination_time.setTimeInMillis(external_res.getAddResponse().getTerminationTime().getTimeInMillis()+time_difference - readd_offset); + long tt = external_res.getAddResponse().getTerminationTime().getTimeInMillis()+time_difference - readd_offset; + termination_time.setTimeInMillis(tt); + logger.finer("Will try to re-add entry for "+ in.getAdd().getMemberEPR().getAddress().getStringValue() + " at: "+termination_time.getTime().toString()); } catch (Exception e) { logger.log(Level.WARNING,"Could not connect to external Registry at "+ external_registry_url,e); } Modified: unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/RegistryEntryImpl.java =================================================================== --- unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/RegistryEntryImpl.java 2007-05-23 07:32:18 UTC (rev 860) +++ unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/RegistryEntryImpl.java 2007-05-23 07:58:10 UTC (rev 861) @@ -32,12 +32,9 @@ package de.fzj.unicore.uas.impl.registry; -import java.util.Map; - import org.oasisOpen.docs.wsrf.sg2.ServiceGroupEPRDocument; import org.w3.x2005.x08.addressing.EndpointReferenceType; -import de.fzj.unicore.uas.UAS; import de.fzj.unicore.wsrflite.Kernel; import de.fzj.unicore.wsrflite.messaging.Message; import de.fzj.unicore.wsrflite.utils.Utilities; @@ -47,37 +44,15 @@ private static final long serialVersionUID = 5328852055025059966L; - public static final String CHECK_LIVE_SERVICE="uas.registry.check.is_alive"; - /** - * if the CHECK_LIVE_SERVICE property is set to true, - * this checks whether the target service (member) is live - */ - @Override - public boolean isExpired() { - return super.isExpired(); - } - @Override - public void initialise(String serviceName, Map<String, Object> initObjs) throws Exception{ - super.initialise(serviceName, initObjs); - //set tt to infinite if we are checking for live services - try{ - if("true".equalsIgnoreCase(UAS.getProperty(CHECK_LIVE_SERVICE))){ - setTerminationTime(null); - } - }catch(Exception e){ - - } - - } - /** * resource-specific destruction: send message about our demise */ @Override public void destroy() { try{ + logger.info(this.getUniqueID() +" Destroying RegistryEntry with id "+this.getUniqueID()); EndpointReferenceType sg=((ServiceGroupEPRDocument)getResourceProperty(RPServiceGroupEPR)[0]).getServiceGroupEPR(); String id=Utilities.extractResourceID(sg); Message m=new Message(null,null,getUniqueID()); Modified: unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/RegistryEntryUpdater.java =================================================================== --- unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/RegistryEntryUpdater.java 2007-05-23 07:32:18 UTC (rev 860) +++ unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/RegistryEntryUpdater.java 2007-05-23 07:58:10 UTC (rev 861) @@ -31,7 +31,7 @@ ********************************************************************************/ package de.fzj.unicore.uas.impl.registry; -import java.util.Iterator; +import java.util.Calendar; import java.util.logging.Level; import java.util.logging.Logger; @@ -43,8 +43,10 @@ import de.fzj.unicore.uas.client.BaseUASClient; import de.fzj.unicore.wsrflite.Home; +import de.fzj.unicore.wsrflite.Kernel; +import de.fzj.unicore.wsrflite.exceptions.ResourceUnknownException; import de.fzj.unicore.wsrflite.impl.ExpiryChecker; -import de.fzj.unicore.wsrflite.xmlbeans.exceptions.ResourceUnknownFault; +import de.fzj.unicore.wsrflite.utils.Utilities; import de.fzj.unicore.wsrflite.xmlbeans.sg.impl.ServiceGroupEntryImpl; /** @@ -52,86 +54,83 @@ * */ public class RegistryEntryUpdater extends ExpiryChecker { - + protected static Logger logger=Logger.getLogger(RegistryEntryUpdater.class.getName()); - - public RegistryEntryUpdater(Home home, String[] initialInstanceIDs) { - super(home,initialInstanceIDs); - this.home=home; - } - - public void run(){ - //logger.info("running..."); - for(Iterator<String> i=list.iterator();i.hasNext();){ - String l=i.next(); - try{ - - RegistryEntryImpl entry=(RegistryEntryImpl)home.getWSRFServiceInstance(l); - - if(entry.isExpired()) + + + @Override + public boolean process(Home home, String id) { + String serviceName = home.getServiceName(); + try{ + RegistryEntryImpl entry=(RegistryEntryImpl)home.getWSRFServiceInstance(id); + + GetResourcePropertyDocument req=GetResourcePropertyDocument.Factory.newInstance(); + req.setGetResourceProperty(ServiceGroupEntryImpl.RPMemberEPR); + GetResourcePropertyResponseDocument res=entry.GetResourceProperty(req); + MemberEPRDocument memberEprDoc = MemberEPRDocument.Factory.parse(res.getGetResourcePropertyResponse().newInputStream()); + EndpointReferenceType memberEpr = memberEprDoc.getMemberEPR(); + + // for WSRF service instances: check if instance still alive +// // use UAS Client because of need for security for uas services + if(memberEpr.getAddress().getStringValue().toLowerCase().contains("?res=")) + { + try { - GetResourcePropertyDocument req=GetResourcePropertyDocument.Factory.newInstance(); - req.setGetResourceProperty(ServiceGroupEntryImpl.RPMemberEPR); - GetResourcePropertyResponseDocument res=entry.GetResourceProperty(req); - MemberEPRDocument memberEprDoc = MemberEPRDocument.Factory.parse(res.getGetResourcePropertyResponse().newInputStream()); - EndpointReferenceType memberEpr = memberEprDoc.getMemberEPR(); - - // for WSRF service instances: check if instance still alive -// // use UAS Client because of need for security for uas services - if(memberEpr.getAddress().getStringValue().toLowerCase().contains("?res=")) - { - try - { - if(logger.isLoggable(Level.FINER)){ - logger.log(Level.FINER,"Alive check: "+memberEpr.getAddress().getStringValue()); - } - BaseUASClient client = new BaseUASClient(memberEpr.getAddress().getStringValue(),memberEpr); - client.getTerminationTime(); - } - catch (Exception e) - { - home.destroyWSRFServiceInstance(l); - entry.destroy(); - i.remove(); - logger.log(Level.WARNING,"Could not reach WSRF instance. Destroyed entry.",e); - continue; - } - + if(logger.isLoggable(Level.FINER)){ + logger.log(Level.FINER,"Alive check: "+memberEpr.getAddress().getStringValue()); } - - try - { - logger.fine("Trying to re-add service to registry: " +memberEpr.getAddress().getStringValue()); - reAdd(memberEpr); - } - catch(Exception e) - { - logger.log(Level.WARNING,"Error re-adding service entry: ",e); - } + home.getWSRFServiceInstance(id); + + } + catch (Exception e) + { + logger.log(Level.WARNING,"Could not find WSRF instance in virtual machine. Destroying entry.",e); + entry.destroy(); + home.destroyWSRFServiceInstance(id); +// instance is invalid and should be removed from all checks + return false; } - + + try { + BaseUASClient client = new BaseUASClient(memberEpr.getAddress().getStringValue(),memberEpr); + client.getCurrentTime(); + + } catch (Exception e) { + logger.log(Level.WARNING,"Could not reach WSRF instance via web service call. Not publishing entry to external registry.",e); +// instance is still valid + return true; + } + } - catch(ResourceUnknownFault f){ - i.remove(); - logger.log(Level.INFO,"Destroyed entry "+l); + + try + { + logger.fine("Trying to re-add service to registry: " +memberEpr.getAddress().getStringValue()); + reAdd(memberEpr); } - catch(Exception e){ - logger.log(Level.WARNING,"Instance id:"+l,e); - } + catch(Exception e) + { + logger.log(Level.WARNING,"Error re-adding service entry: ",e); + } } + + catch(Exception e){ + logger.log(Level.WARNING,"Could not update WSRF instance of type "+serviceName+" and id: "+id,e); + } + + // instance is still valid + return true; } - - - - - + + protected void reAdd(EndpointReferenceType memberEpr) throws Exception { AddDocument add = AddDocument.Factory.newInstance(); add.addNewAdd().setMemberEPR(memberEpr); add.getAdd().setInitialTerminationTime(null); RegistryHandler.getRegistryClient().addRegistryEntry(add); - } + + } Modified: unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/RegistryHandler.java =================================================================== --- unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/RegistryHandler.java 2007-05-23 07:32:18 UTC (rev 860) +++ unicorex/uas-core/trunk/src/main/java/de/fzj/unicore/uas/impl/registry/RegistryHandler.java 2007-05-23 07:58:10 UTC (rev 861) @@ -86,11 +86,9 @@ String resID = "default_registry"; registryURL = Utilities.makeAddress(UAS.REG,resID); - registryEPR = EndpointReferenceType.Factory.newInstance(); - registryEPR.addNewAddress().setStringValue(registryURL); - AddressingUtil.addUGSRefparamToEpr(registryEPR); + registryEPR = Utilities.makeEPR(UAS.REG, resID); - logger.info("Setting up registry for URL="+registryEPR.getAddress().getStringValue()); + logger.config("Setting up registry for URL="+registryURL); getExternalRegistryURL(); Home regHome=Kernel.getKernel().getServiceHome(UAS.REG); @@ -101,12 +99,12 @@ regHome.getWSRFServiceInstance(resID); registryClient = new RegistryClient(registryURL,registryEPR,sec); registryClient.getCurrentTime(); - logger.info("Registry has already been set up."); + logger.config("Registry has already been set up."); } catch(Exception e) { try { - logger.info("Trying to start up local registry."); + logger.config("Trying to start up local registry."); Map<String,Object>map=new HashMap<String,Object>(); map.put(WSResourceImpl.INIT_UNIQUE_ID,resID); //set lifetime to three months @@ -116,7 +114,7 @@ regHome.getWSRFServiceInstance(regHome.createWSRFServiceInstance(map)); registryClient = new RegistryClient(registryURL,registryEPR,sec); registryClient.getCurrentTime(); - logger.info("Added '"+resID+"' resource to service "+UAS.REG); + logger.config("Added '"+resID+"' resource to service "+UAS.REG); } catch (Exception ex) { logger.log(Level.WARNING,"Could not start up local registry!",ex); @@ -130,8 +128,11 @@ } public static String getExternalRegistryURL(){ + String wsaTo = null, resID = null; - String wsaTo = null, resID = null; + if(isGlobalRegistry()) logger.config("This is a global registry. No external registry used."); + if(!usesExternalRegistry()) logger.config("Usage of external registry is switched off by property "+UAS.EXTERNAL_REGISTRY_USE +". No external registry used."); + if(isGlobalRegistry() || !usesExternalRegistry()) { externalRegistryEPR = null; @@ -140,6 +141,7 @@ } else { + logger.config("Determining Address of external registry..."); boolean autodiscover = true; try { String autodiscover_prop = UAS.getProperty(UAS.REGISTRY_AUTODISCOVER); @@ -147,19 +149,25 @@ } catch (Exception e) { logger.log(Level.WARNING,"Invalid value for property "+UAS.REGISTRY_AUTODISCOVER+"! Only values \"true\" and \"false\" allowed.",e); } - if(autodiscover && scheduledExecutor == null) + if(autodiscover) { logger.config("Setting up auto-discovery of external registry."); - MulticastRegistryFinder finder = new MulticastRegistryFinder(); - finder.run(); - scheduledExecutor = Executors.newScheduledThreadPool(1); - scheduledExecutor.scheduleAtFixedRate(finder,period,initial,TimeUnit.SECONDS); + + if(scheduledExecutor == null) + { + logger.config("Scheduling repeated auto-discovery."); + MulticastRegistryFinder finder = new MulticastRegistryFinder(); + finder.run(); + scheduledExecutor = Executors.newScheduledThreadPool(1); + scheduledExecutor.scheduleAtFixedRate(finder,period,initial,TimeUnit.SECONDS); + } } + else logger.config("Auto-discovery of external registry switched off."); // if autodiscovery switched off or failed apply user given registry address as fallback if(externalRegistryURL == null) { - logger.config("Registry auto-discovery switched off or failed. Trying to use manual settings for external registry."); + logger.config("Trying to use manual settings for external registry."); externalRegistryURL = UAS.getProperty(UAS.EXTERNAL_REGISTRY_KEY); if(externalRegistryURL!=null){ @@ -226,6 +234,7 @@ isGlobalRegistry = Boolean.parseBoolean(UAS.getProperty(UAS.IS_GLOBAL_REGISTRY)); } catch (Exception e) { + logger.log(Level.WARNING,"Could not read property "+UAS.IS_GLOBAL_REGISTRY+"! Assuming value 'false'. ",e); isGlobalRegistry = false; } return isGlobalRegistry; @@ -240,6 +249,7 @@ usesExternalRegistry = Boolean.parseBoolean(UAS.getProperty(UAS.EXTERNAL_REGISTRY_USE)); } catch (Exception e) { + logger.log(Level.WARNING,"Could not read property "+UAS.EXTERNAL_REGISTRY_USE+"! Assuming value 'false'.",e); usesExternalRegistry = false; } return usesExternalRegistry; Modified: wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/impl/DefaultHome.java =================================================================== --- wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/impl/DefaultHome.java 2007-05-23 07:32:18 UTC (rev 860) +++ wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/impl/DefaultHome.java 2007-05-23 07:58:10 UTC (rev 861) @@ -41,6 +41,7 @@ import java.util.Map; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; @@ -106,11 +107,12 @@ public static final String EXPIRYCHECK_PERIOD="expirycheck.period"; /** - * this takes care of removing expired WS-Resources + * this takes care of removing expired WS-Resources etc. */ - protected ExpiryChecker expiryChecker; + protected InstanceChecking instanceChecking; + protected InstanceChecker expiryChecker; - protected ScheduledExecutorService reaper; + protected ScheduledExecutorService instanceCheckingPool; public DefaultHome(){ terminationTimes=new HashMap<String,Calendar>(); @@ -136,13 +138,23 @@ * @see EXPIRYCHECK_INITIAL * @see EXPIRYCHECK_PERIOD */ + protected void initExpiryCheck(){ String[] uniqueIDs=serviceInstances.getUniqueIDs(); logger.info("Have "+uniqueIDs.length+" instances from permanent storage"); setupTerminationTimeMap(uniqueIDs); - expiryChecker = new ExpiryChecker(this,uniqueIDs); - reaper = Executors.newScheduledThreadPool(1); + instanceChecking = new InstanceChecking(this,uniqueIDs); + expiryChecker = new ExpiryChecker(); + instanceChecking.addChecker(expiryChecker); + + instanceCheckingPool = Executors.newScheduledThreadPool(1,new ThreadFactory(){ + public Thread newThread(Runnable r) { + Thread t = new Thread(r); + t.setName("Instance Checker for "+serviceName); + return t; + } + }); int initial; int period; try{ @@ -156,7 +168,7 @@ period=3; } logger.info("Expiry thread scheduled at a period of "+period+" secs."); - reaper.scheduleAtFixedRate(expiryChecker,period,initial,TimeUnit.SECONDS); + instanceCheckingPool.scheduleAtFixedRate(instanceChecking,period,initial,TimeUnit.SECONDS); } @@ -200,7 +212,7 @@ if(initObjs==null)initObjs=new HashMap<String,Object>(); newInstance.initialise(serviceName, initObjs); storeNewInstance(newInstance); - expiryChecker.add(newInstance.getUniqueID()); + instanceChecking.add(newInstance.getUniqueID()); return newInstance.getUniqueID(); } catch(Exception e){ Modified: wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/impl/ExpiryChecker.java =================================================================== --- wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/impl/ExpiryChecker.java 2007-05-23 07:32:18 UTC (rev 860) +++ wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/impl/ExpiryChecker.java 2007-05-23 07:58:10 UTC (rev 861) @@ -38,6 +38,7 @@ import java.util.logging.Logger; import de.fzj.unicore.wsrflite.Home; +import de.fzj.unicore.wsrflite.Kernel; import de.fzj.unicore.wsrflite.exceptions.ResourceUnknownException; /** @@ -49,34 +50,31 @@ * @author schuller * @version $Id: ExpiryChecker.java,v 1.9 2007/01/03 15:25:19 bschuller Exp $ */ -public class ExpiryChecker extends InstanceCheckerImpl { +public class ExpiryChecker implements InstanceChecker { protected static Logger logger=Logger.getLogger(ExpiryChecker.class.getName()); - private String serviceName; - public ExpiryChecker(Home home, String[] initialInstanceIDs){ - super(home,initialInstanceIDs); - this.serviceName=home.getServiceName(); - } - - @Override - public boolean check(String id)throws ResourceUnknownException { + public boolean check(Home home, String id)throws ResourceUnknownException { Calendar c=home.getTerminationTime(id); if(c==null)return false; return (c.compareTo(Calendar.getInstance())<=0); } - @Override - public void process(String id) { + public boolean process(Home home, String id) { + String serviceName = home.getServiceName(); try{ logger.log(Level.FINER, "Destroying "+serviceName+"<"+id+">"); home.getWSRFServiceInstance(id).destroy(); home.destroyWSRFServiceInstance(id); + // instance is invalid and should be removed from all checks + return false; }catch(Exception e){ logger.log(Level.WARNING,"Could not destroy instance "+serviceName+"<"+id+">",e); + // instance should be checked again for destruction later + return true; } } + - } Modified: wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/impl/InstanceChecker.java =================================================================== --- wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/impl/InstanceChecker.java 2007-05-23 07:32:18 UTC (rev 860) +++ wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/impl/InstanceChecker.java 2007-05-23 07:58:10 UTC (rev 861) @@ -1,5 +1,6 @@ package de.fzj.unicore.wsrflite.impl; +import de.fzj.unicore.wsrflite.Home; import de.fzj.unicore.wsrflite.exceptions.ResourceUnknownException; @@ -10,17 +11,14 @@ * @param uniqueID - a WSRFInstance id * @return */ - public boolean check(String uniqueID) throws ResourceUnknownException; + public boolean check(Home home, String uniqueID) throws ResourceUnknownException; /** * perform processing on the instance (in case check() hits) * @param uniqueID - a WSRFInstance id + * @return true if instance is still valid. If it is invalid, it will be removed. */ - public void process(String uniqueID) throws ResourceUnknownException; + public boolean process(Home home, String uniqueID) throws ResourceUnknownException; - /** - * should the instance be removed? - * @return true if instance is to be removed - */ - public boolean removeOnHit(); + } \ No newline at end of file Added: wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/impl/InstanceChecking.java =================================================================== --- wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/impl/InstanceChecking.java (rev 0) +++ wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/impl/InstanceChecking.java 2007-05-23 07:58:10 UTC (rev 861) @@ -0,0 +1,133 @@ +/********************************************************************************* + * Copyright (c) 2006 Forschungszentrum Juelich GmbH + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * (1) Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer at the end. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * (2) Neither the name of Forschungszentrum Juelich GmbH nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * DISCLAIMER + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + ********************************************************************************/ + + +package de.fzj.unicore.wsrflite.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import de.fzj.unicore.wsrflite.Home; +import de.fzj.unicore.wsrflite.exceptions.ResourceUnknownException; + +/** + * Run checks on all wsrf instances of a given service + * + * @author schuller + * @version $Id: InstanceCheckerImpl.java,v 1.1 2007/01/03 15:25:19 bschuller Exp $ + */ +public class InstanceChecking implements Runnable { + protected static Logger logger=Logger.getLogger(InstanceChecking.class.getName()); + //list of uniqueIDs + protected List<String> list; + private Home home; + + + protected List<InstanceChecker> checkers; + + + public InstanceChecking(Home home, String[] initialInstanceIDs){ + this.home=home; + list=Collections.synchronizedList(new ArrayList<String>()); + checkers=Collections.synchronizedList(new ArrayList<InstanceChecker>()); + for(String s: initialInstanceIDs){ + add(s); + } + } + + public boolean add(String itemId){ + synchronized(list){ + return list.add(itemId); + } + } + + public boolean remove(String item){ + synchronized(list){ + return list.remove(item); + } + } + + + public boolean addChecker(InstanceChecker c){ + return checkers.add(c); + } + + public boolean removeChecker(InstanceChecker c){ + return checkers.remove(c); + } + + /** + * template method that + * checks the condition on each instance, + * performs some action, + * + * and removes the instance from the list if it is not valid anymore + */ + public void run(){ + if(logger.isLoggable(Level.FINEST))logger.finest("Instance Checking running..."); + synchronized(list){ + String serviceName = home.getServiceName(); + for(Iterator<String> i=list.iterator();i.hasNext();){ + String uniqueID=i.next(); + if(logger.isLoggable(Level.FINEST))logger.finest("Checking instance of type "+serviceName+" and id "+uniqueID); + boolean instanceValid = true; + try{ + for(InstanceChecker ic: checkers){ + if(logger.isLoggable(Level.FINEST))logger.finest("Testing Checker "+ic.getClass().getName()); + if(ic.check(home,uniqueID)){ + if(logger.isLoggable(Level.FINEST))logger.finest("Applying Checker "+ic.getClass().getName()); + instanceValid = ic.process(home,uniqueID); + } + } + if(!instanceValid){ + logger.log(Level.INFO,"Removing instance "+serviceName+"<"+uniqueID+">"); + i.remove(); + } + }catch(ResourceUnknownException f){ + logger.log(Level.INFO,"Unknown instance "+serviceName+"<"+uniqueID+">, removing."); + i.remove(); + } + //catch Throwable here to avoid the checker going down in case + //of an uncaught exception + catch(Throwable e){ + logger.log(Level.WARNING,"Instance of type "+serviceName+" with id <"+uniqueID+">",e); + } + } + } + } + + +} Modified: wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/impl/WSResourceImpl.java =================================================================== --- wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/impl/WSResourceImpl.java 2007-05-23 07:32:18 UTC (rev 860) +++ wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/impl/WSResourceImpl.java 2007-05-23 07:58:10 UTC (rev 861) @@ -347,6 +347,7 @@ XmlCursor c=r.newCursor(); c.toFirstContentToken(); for(XmlObject o:os){ + if(o== null) continue; XmlCursor c1=o.newCursor(); c1.toFirstContentToken(); c1.copyXml(c); Modified: wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/sg/impl/ServiceGroupRegistrationImpl.java =================================================================== --- wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/sg/impl/ServiceGroupRegistrationImpl.java 2007-05-23 07:32:18 UTC (rev 860) +++ wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/sg/impl/ServiceGroupRegistrationImpl.java 2007-05-23 07:58:10 UTC (rev 861) @@ -43,9 +43,6 @@ import org.apache.xmlbeans.XmlDuration; import org.apache.xmlbeans.XmlObject; import org.oasisOpen.docs.wsrf.rl2.SetTerminationTimeDocument; -import org.oasisOpen.docs.wsrf.rl2.TerminationTimeDocument; -import org.oasisOpen.docs.wsrf.rp2.GetResourcePropertyDocument; -import org.oasisOpen.docs.wsrf.rp2.GetResourcePropertyResponseDocument; import org.oasisOpen.docs.wsrf.sg2.AddDocument; import org.oasisOpen.docs.wsrf.sg2.AddResponseDocument; import org.oasisOpen.docs.wsrf.sg2.ContentType; @@ -54,10 +51,12 @@ import de.fzj.unicore.wsrflite.Home; import de.fzj.unicore.wsrflite.Kernel; +import de.fzj.unicore.wsrflite.impl.WSRFInstanceImpl; import de.fzj.unicore.wsrflite.persistence.PersistenceManager; import de.fzj.unicore.wsrflite.utils.Utilities; import de.fzj.unicore.wsrflite.xmlbeans.BaseFault; import de.fzj.unicore.wsrflite.xmlbeans.WSResource; +import de.fzj.unicore.wsrflite.xmlbeans.exceptions.ResourceUnknownFault; import de.fzj.unicore.wsrflite.xmlbeans.sg.ServiceGroupEntry; import de.fzj.unicore.wsrflite.xmlbeans.sg.ServiceGroupRegistration; @@ -66,182 +65,171 @@ * @author schuller * @version $Id: ServiceGroupRegistrationImpl.java,v 1.7 2006/11/13 10:16:27 bdemuth Exp $ */ -public class ServiceGroupRegistrationImpl extends ServiceGroupImpl implements - ServiceGroupRegistration { +public class ServiceGroupRegistrationImpl extends ServiceGroupImpl implements ServiceGroupRegistration { protected static final long serialVersionUID=980349444L; - protected static long defaultTerminationTime = 300; /** * add a service to this service group. * this will create a new ws resource to represent the entry. */ public AddResponseDocument Add(AddDocument in) throws BaseFault { - try{ - if(logger.isLoggable(Level.FINEST))logger.finest("Add:"+in); - EndpointReferenceType epr=in.getAdd().getMemberEPR(); - - try { - defaultTerminationTime = Long.parseLong(Kernel.getKernel().getProperty(Kernel.WSRF_SGENTRY_TERMINATION_TIME)); - } catch (Exception e) { + AddResponseDocument res=AddResponseDocument.Factory.newInstance(); + res.addNewAddResponse(); + try{ + if(logger.isLoggable(Level.FINEST))logger.finest("Add:"+in); + EndpointReferenceType epr=in.getAdd().getMemberEPR(); + +// check if entry already exists in service group + EntryDocument entry=getEntry(epr); + EndpointReferenceType sgeEpr = null; + Calendar tt = getDefaultTerminationTime(); + try{ + Calendar requestedTT = makeCalendar(in.getAdd().getInitialTerminationTime()); + if(requestedTT!=null) + { + tt = requestedTT; + logger.finer("Termination time requested: "+ tt.getTime().toString()+". Using this instead of default value."); + } + }catch(Exception e){ + logger.log(Level.SEVERE,"Error setting initial TT to requested value.",e); + } + if(entry!=null) + { +// only reset termination time for entry + try { + logger.finer("Refreshing termination time for entry: "+epr.getAddress().getStringValue()); + sgeEpr=entry.getEntry().getServiceGroupEntryEPR(); + logger.finer("Searching for uid: "+Utilities.extractResourceID(sgeEpr)); + setSGETerminationTime(sgeEpr, tt); + res.getAddResponse().setTerminationTime(tt); + res.getAddResponse().setServiceGroupEntryReference(sgeEpr); + return res; + + } catch (ResourceUnknownFault e) { + // sgEntry has been destroyed in between + // => create new Entry + } + } + + // create new entry + logger.finer("Creating new entry for service: "+epr.getAddress().getStringValue()); + ContentType content=in.getAdd().getContent(); + entry=EntryDocument.Factory.newInstance(); + entry.addNewEntry().setContent(content); + entry.getEntry().setMemberServiceEPR(epr); + Map<String,Object>map=new HashMap<String,Object>(); + + map.put(WSRFInstanceImpl.INIT_INITIAL_TERMINATION_TIME,tt); + map.put(ServiceGroupEntryImpl.INIT_MEMBER_EPR,epr); + map.put(ServiceGroupEntryImpl.INIT_CONTENT,content); + EndpointReferenceType entryEpr = Utilities.makeEPR(getServiceName(),getUniqueID()); + map.put(ServiceGroupEntryImpl.INIT_SERVICEGROUP_EPR,entryEpr); + sgeEpr=createServiceGroupEntry(map); + entry.getEntry().setServiceGroupEntryEPR(sgeEpr); + addEntry(entry); + logger.finer("Assigned uid: "+Utilities.extractResourceID(sgeEpr)); + res.getAddResponse().setTerminationTime(tt); + res.getAddResponse().setServiceGroupEntryReference(sgeEpr); + return res; + + }catch(Exception e){ + logger.log(Level.SEVERE,"Error adding",e); + throw BaseFault.createFault(e.getMessage()); + } } - - Calendar tt = Calendar.getInstance(); - tt.setTimeInMillis(System.currentTimeMillis()+defaultTerminationTime*1000); - try{ - Calendar requested_tt = makeCalendar(in.getAdd().getInitialTerminationTime()); - if(requested_tt!=null) - { - tt = requested_tt; - logger.finer("Termination time requested: "+ tt.getTime().toString()+". Using this instead of default value."); + protected EndpointReferenceType createServiceGroupEntry(Map<String,Object>initObjs)throws Exception{ + Home sgeHome=Kernel.getKernel().getServiceHome(ServiceGroupEntry.SERVICENAME); + String uID=sgeHome.createWSRFServiceInstance(initObjs); + EndpointReferenceType epr=EndpointReferenceType.Factory.newInstance(); + epr.addNewAddress().setStringValue(Utilities.makeAddress(ServiceGroupEntry.SERVICENAME,uID)); + return epr; + } + + /** + * make a Calendar instance from the initial TT as supplied to Add()<br/> + * the SG spec says this is either xsd:dateTime or xsd:duration + * @param initialTT + * @return Calendar + */ + public Calendar makeCalendar(Object initialTT){ + if(initialTT==null)return null; + Calendar c=null; + try{ + XmlDateTime d=XmlDateTime.Factory.newValue(initialTT); + c=d.getCalendarValue(); + return c; } - }catch(Exception e){ - logger.log(Level.SEVERE,"Error setting initial TT to requested value.",e); + catch(Exception e){} + + try{ + XmlDuration d=XmlDuration.Factory.newValue(initialTT); + GDuration duration=d.getGDurationValue(); + GDateBuilder b=new GDateBuilder(); + b.addGDuration(duration); + c=Calendar.getInstance(); + c.setTime(b.getDate()); + return c; + }catch(Exception e){} + return null; } - -// check if entry already exists in service group - EntryDocument entry=getEntry(epr); - EndpointReferenceType sgeEpr = null; - if(entry==null){ - // no => create new entry - logger.finer("Creating new entry for service: "+epr.getAddress().getStringValue()); - ContentType content=in.getAdd().getContent(); - entry=EntryDocument.Factory.newInstance(); - entry.addNewEntry().setContent(content); - entry.getEntry().setMemberServiceEPR(epr); - Map<String,Object>map=new HashMap<String,Object>(); - map.put(INIT_INITIAL_TERMINATION_TIME,tt); - map.put(ServiceGroupEntryImpl.INIT_MEMBER_EPR,epr); - map.put(ServiceGroupEntryImpl.INIT_CONTENT,content); - map.put(ServiceGroupEntryImpl.INIT_SERVICEGROUP_EPR, - Utilities.makeEPR(getServiceName(),getUniqueID())); - sgeEpr=createServiceGroupEntry(map); - entry.getEntry().setServiceGroupEntryEPR(sgeEpr); - addEntry(entry); - logger.finer("Assigned uid: "+Utilities.extractResourceID(sgeEpr)); + + + + public EntryDocument getEntry(EndpointReferenceType epr){ +// logger.info("Looking for epr: " +epr.getAddress().getStringValue()); + XmlObject[]entries=getResourceProperty(RPEntry); + if(entries==null)return null; + for(XmlObject o: entries){ + EntryDocument entry=(EntryDocument)o; + EndpointReferenceType member=entry.getEntry().getMemberServiceEPR(); +// logger.info("Comparing to: "+member.getAddress().getStringValue()); + if( equalEPRs(member,epr)){ +// logger.info("Eprs are equal."); + return entry; + } + } + + return null; } - - else + + public boolean equalEPRs(EndpointReferenceType epr1, EndpointReferenceType epr2) { - // yes => only reset termination time for entry - // TODO make this more thread-safe? right now, the entry might be destroyed - // when expired before its termination time is reset => ResourceUnknownFault thrown - logger.finer("Refreshing termination time for entry: "+epr.getAddress().getStringValue()); - sgeEpr=entry.getEntry().getServiceGroupEntryEPR(); - logger.finer("Searching for uid: "+Utilities.extractResourceID(sgeEpr)); - setSGETerminationTime(sgeEpr, tt); + return epr1.getAddress().getStringValue().equalsIgnoreCase(epr2.getAddress().getStringValue()); } - - AddResponseDocument res=AddResponseDocument.Factory.newInstance(); - res.addNewAddResponse(); -// Calendar tt=getSGETerminationTime(Utilities.extractResourceID(sgeEpr)); -// if(tt!=null)res.getAddResponse().setTerminationTime(tt); -// else - res.getAddResponse().setTerminationTime(tt); - res.getAddResponse().setServiceGroupEntryReference(sgeEpr); - - return res; - - }catch(Exception e){ - logger.log(Level.SEVERE,"Error adding",e); - throw BaseFault.createFault(e.getMessage()); - } - - } - protected EndpointReferenceType createServiceGroupEntry(Map<String,Object>initObjs)throws Exception{ - Home sgeHome=Kernel.getKernel().getServiceHome(ServiceGroupEntry.SERVICENAME); - String uID=sgeHome.createWSRFServiceInstance(initObjs); - EndpointReferenceType epr=EndpointReferenceType.Factory.newInstance(); - epr.addNewAddress().setStringValue(Utilities.makeAddress(ServiceGroupEntry.SERVICENAME,uID)); - return epr; - } - - /** - * get the tt of the specified service group entry wsresource - * @param uid - * @return Calendar - * @throws Exception - */ - protected Calendar getSGETerminationTime(EndpointReferenceType epr)throws Exception { - Home sgeHome=Kernel.getKernel().getServiceHome(ServiceGroupEntry.SERVICENAME); - String uID=Utilities.extractResourceID(epr); - ServiceGroupEntry sge=(ServiceGroupEntry)sgeHome.getWSRFServiceInstance(uID); - GetResourcePropertyDocument req=GetResourcePropertyDocument.Factory.newInstance(); - req.setGetResourceProperty(WSResource.RPterminationTimeQName); - GetResourcePropertyResponseDocument res=sge.GetResourceProperty(req); - TerminationTimeDocument o=TerminationTimeDocument.Factory.parse(Utilities.extractResourceProperty(res).newInputStream()); - if(o==null)return null; - if(o.getTerminationTime().isNil())return null; - return o.getTerminationTime().getCalendarValue(); - } - - protected void setSGETerminationTime(EndpointReferenceType epr, Calendar tt)throws Exception{ - Home sgeHome=Kernel.getKernel().getServiceHome(ServiceGroupEntry.SERVICENAME); - String uID=Utilities.extractResourceID(epr); - WSResource wsr=(WSResource)sgeHome.getWSRFServiceInstance(uID); - - SetTerminationTimeDocument stt=SetTerminationTimeDocument.Factory.newInstance(); - stt.addNewSetTerminationTime().setRequestedTerminationTime(tt); - logger.log(Level.FINER,"Setting Termination Time of service entry "+epr.getAddress().getStringValue()+ " to "+tt.getTime().toString()); - wsr.SetTerminationTime(stt); - PersistenceManager.persist(wsr); - - } - - - - /** - * make a Calendar instance from the initial TT as supplied to Add()<br/> - * the SG spec says this is either xsd:dateTime or xsd:duration - * @param initialTT - * @return Calendar - */ - protected Calendar makeCalendar(Object initialTT){ - if(initialTT==null)return null; - Calendar c=null; - try{ - XmlDateTime d=XmlDateTime.Factory.newValue(initialTT); - c=d.getCalendarValue(); - return c; - } - catch(Exception e){} - - try{ - XmlDuration d=XmlDuration.Factory.newValue(initialTT); - GDuration duration=d.getGDurationValue(); - GDateBuilder b=new GDateBuilder(); - b.addGDuration(duration); - c=Calendar.getInstance(); - c.setTime(b.getDate()); - return c; - }catch(Exception e){} - return null; - } - - + /** + * set the tt of the specified service group entry wsresource + * @param epr + * @param tt + * @throws Exception + */ + public void setSGETerminationTime(EndpointReferenceType epr, Calendar tt)throws Exception{ + Home sgeHome=Kernel.getKernel().getServiceHome(ServiceGroupEntry.SERVICENAME); + String uID=Utilities.extractResourceID(epr); + WSResource wsr=(WSResource)sgeHome.getWSRFServiceInstance(uID); - protected EntryDocument getEntry(EndpointReferenceType epr){ -// logger.info("Looking for epr: " +epr.getAddress().getStringValue()); - XmlObject[]entries=getResourceProperty(RPEntry); - if(entries==null)return null; - for(XmlObject o: entries){ - EntryDocument entry=(EntryDocument)o; - EndpointReferenceType member=entry.getEntry().getMemberServiceEPR(); -// logger.info("Comparing to: "+member.getAddress().getStringValue()); - if( equalEPRs(member,epr)){ -// logger.info("Eprs are equal."); - return entry; + SetTerminationTimeDocument stt=SetTerminationTimeDocument.Factory.newInstance(); + stt.addNewSetTerminationTime().setRequestedTerminationTime(tt); + logger.log(Level.FINER,"Setting Termination Time of service entry "+epr.getAddress().getStringValue()+ " to "+tt.getTime().toString()); + wsr.SetTerminationTime(stt); + PersistenceManager.persist(wsr); + } - } - - return null; - } + + public Calendar getDefaultTerminationTime() + { + long defaultTerminationTime = 1800; + try { + defaultTerminationTime = Long.parseLong(Kernel.getKernel().getProperty(Kernel.WSRF_SGENTRY_TERMINATION_TIME)); + } catch (Exception e) { + } + + Calendar tt = Calendar.getInstance(); + tt.setTimeInMillis(System.currentTimeMillis()+defaultTerminationTime*1000); + + return tt; + } - protected boolean equalEPRs(EndpointReferenceType epr1, EndpointReferenceType epr2) - { - return epr1.getAddress().getStringValue().equalsIgnoreCase(epr2.getAddress().getStringValue()); - } - } Modified: wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/wsn/impl/NotificationProducerHomeImpl.java =================================================================== --- wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/wsn/impl/NotificationProducerHomeImpl.java 2007-05-23 07:32:18 UTC (rev 860) +++ wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/wsn/impl/NotificationProducerHomeImpl.java 2007-05-23 07:58:10 UTC (rev 861) @@ -90,7 +90,7 @@ * and checks for new events */ protected void startEventChecker(){ - expiryChecker.addChecker(new WSNEventChecker(this)); + instanceChecking.addChecker(new WSNEventChecker()); } } Modified: wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/wsn/impl/WSNEventChecker.java =================================================================== --- wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/wsn/impl/WSNEventChecker.java 2007-05-23 07:32:18 UTC (rev 860) +++ wsrflite/wsrfcore/trunk/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/wsn/impl/WSNEventChecker.java 2007-05-23 07:58:10 UTC (rev 861) @@ -3,6 +3,7 @@ import org.oasisOpen.docs.wsrf.rp2.GetResourcePropertyDocumentDocument1; import de.fzj.unicore.wsrflite.Home; +import de.fzj.unicore.wsrflite.Kernel; import de.fzj.unicore.wsrflite.WSRFInstance; import de.fzj.unicore.wsrflite.exceptions.ResourceUnknownException; import de.fzj.unicore.wsrflite.impl.InstanceChecker; @@ -16,10 +17,8 @@ private GetResourcePropertyDocumentDocument1 in; - private Home service; - public WSNEventChecker(Home service){ - this.service=service; + public WSNEventChecker(){ in=GetResourcePropertyDocumentDocument1.Factory.newInstance(); in.addNewGetResourcePropertyDocument(); } @@ -28,8 +27,8 @@ * this will invoke GetResourcePropertyDocument() and thus events will * be generated */ - public boolean check(String id)throws ResourceUnknownException { - WSRFInstance wsrf=service.getWSRFServiceInstance(id); + public boolean check(Home home, String id)throws ResourceUnknownException { + WSRFInstance wsrf=home.getWSRFServiceInstance(id); try{ ((WSResource)wsrf).GetResourcePropertyDocument(in); }catch(Exception e){ @@ -38,12 +37,10 @@ return false; } - public void process(String id) { - + public boolean process(Home home, String id) { + // do not remove instance + return true; } - public boolean removeOnHit() { - return false; - } } Modified: wsrflite/wsrfcore/trunk/src/test/java/de/fzj/unicore/wsrflite/functional/TestWSResourceHomeImpl.java =================================================================== --- wsrflite/wsrfcore/trunk/src/test/java/de/fzj/unicore/wsrflite/functional/TestWSResourceHomeImpl.java 2007-05-23 07:32:18 UTC (rev 860) +++ wsrflite/wsrfcore/trunk/src/test/java/de/fzj/unicore/wsrflite/functional/TestWSResourceHomeImpl.java 2007-05-23 07:58:10 UTC (rev 861) @@ -13,7 +13,7 @@ } public void runExpiryCheck(){ - expiryChecker.run(); + instanceChecking.run(); } @Override Modified: wsrflite/wsrfcore/trunk/src/test/java/de/fzj/unicore/wsrflite/impl/TestExpireWSResources.java =================================================================== --- wsrflite/wsrfcore/trunk/src/test/java/de/fzj/unicore/wsrflite/impl/TestExpireWSResources.java 2007-05-23 07:32:18 UTC (rev 860) +++ wsrflite/wsrfcore/trunk/src/test/java/de/fzj/unicore/wsrflite/impl/TestExpireWSResources.java 2007-05-23 07:58:10 UTC (rev 861) @@ -115,21 +115,23 @@ public void test1(){ - ExpiryChecker ex=new ExpiryChecker(home, new String[0]); + InstanceChecking ic = new InstanceChecking(home, new String[0]); - assertTrue(ex.add(item.getUniqueID())); - ex.run(); - assertFalse(ex.remove(item.getUniqueID())); + assertTrue(ic.add(item.getUniqueID())); + assertTrue(ic.addChecker(new ExpiryChecker())); + ic.run(); + assertFalse(ic.remove(item.getUniqueID())); } public void testScheduled() throws Exception{ - ExpiryChecker ex=new ExpiryChecker(home,new String[0]); - assertTrue(ex.add(item.getUniqueID())); + InstanceChecking ic = new InstanceChecking(home, new String[0]); + assertTrue(ic.add(item.getUniqueID())); + assertTrue(ic.addChecker(new ExpiryChecker())); ScheduledExecutorService reaper = Executors.newScheduledThreadPool(1); //check instances for expiry every 10 milliseconds - reaper.scheduleAtFixedRate(ex,10,10,TimeUnit.MILLISECONDS); + reaper.scheduleAtFixedRate(ic,10,10,TimeUnit.MILLISECONDS); Thread.sleep(100); - assertFalse(ex.list.contains(item.getUniqueID())); + assertFalse(ic.list.contains(item.getUniqueID())); assertTrue(destroyed); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |