You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrp4j-dev@portals.apache.org by es...@apache.org on 2007/08/21 06:35:39 UTC
svn commit: r567947 [1/3] - in
/portals/wsrp4j/trunk/commons-producer/src/java/org/apache/wsrp4j/commons/producer:
driver/ConsumerRegistryImpl.java driver/WSRPEngine.java
interfaces/ConsumerRegistry.java
Author: esm
Date: Mon Aug 20 21:35:37 2007
New Revision: 567947
URL: http://svn.apache.org/viewvc?rev=567947&view=rev
Log:
[WSRP4J-94]: Updated constructors for Spring dependency injection.
Code formatting.
Updated/removed logging statements.
Added modify() method to the ConsumerRegistry interface, and its impl.
WSRPEngine has updated cookie checking/handling in getMarkup() and performBlockingInteration()
Modified:
portals/wsrp4j/trunk/commons-producer/src/java/org/apache/wsrp4j/commons/producer/driver/ConsumerRegistryImpl.java
portals/wsrp4j/trunk/commons-producer/src/java/org/apache/wsrp4j/commons/producer/driver/WSRPEngine.java
portals/wsrp4j/trunk/commons-producer/src/java/org/apache/wsrp4j/commons/producer/interfaces/ConsumerRegistry.java
Modified: portals/wsrp4j/trunk/commons-producer/src/java/org/apache/wsrp4j/commons/producer/driver/ConsumerRegistryImpl.java
URL: http://svn.apache.org/viewvc/portals/wsrp4j/trunk/commons-producer/src/java/org/apache/wsrp4j/commons/producer/driver/ConsumerRegistryImpl.java?rev=567947&r1=567946&r2=567947&view=diff
==============================================================================
--- portals/wsrp4j/trunk/commons-producer/src/java/org/apache/wsrp4j/commons/producer/driver/ConsumerRegistryImpl.java (original)
+++ portals/wsrp4j/trunk/commons-producer/src/java/org/apache/wsrp4j/commons/producer/driver/ConsumerRegistryImpl.java Mon Aug 20 21:35:37 2007
@@ -19,380 +19,348 @@
import java.util.Iterator;
import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import oasis.names.tc.wsrp.v1.types.RegistrationContext;
import oasis.names.tc.wsrp.v1.types.RegistrationData;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.wsrp4j.commons.exception.WSRPException;
-
import org.apache.wsrp4j.commons.persistence.PersistentDataObject;
-import org.apache.wsrp4j.commons.persistence.ProducerPersistentFactory;
import org.apache.wsrp4j.commons.persistence.PersistentHandler;
-import org.apache.wsrp4j.commons.persistence.driver.PersistentAccess;
-
+import org.apache.wsrp4j.commons.persistence.ProducerPersistentFactory;
import org.apache.wsrp4j.commons.producer.interfaces.ConsumerRegistry;
import org.apache.wsrp4j.commons.producer.interfaces.Registration;
-import org.apache.wsrp4j.commons.producer.provider.interfaces.
- DescriptionHandler;
-import org.apache.wsrp4j.commons.producer.provider.interfaces.Provider;
-
+import org.apache.wsrp4j.commons.producer.provider.interfaces.DescriptionHandler;
import org.apache.wsrp4j.commons.util.HandleGenerator;
-import org.apache.wsrp4j.commons.util.impl.HandleGeneratorFactoryImpl;
-import org.apache.wsrp4j.commons.util.Utility;
/**
- * <p>This class implements the ConsumerRegistry interface. All registrations
- * are kept within a hashmap associating registration handles (keys) with
- * registration-objects (values). Provides different access methods.</p>
- * <p>TODO:
+ * <p>
+ * This class implements the ConsumerRegistry interface. All registrations are
+ * kept within a hashmap associating registration handles (keys) with
+ * registration-objects (values). Provides different access methods.
+ * </p>
+ * <p>
+ * TODO:
* <ul>
- * <li>Synchronization aspects are not considered so far. This could be
- * achieved by using a hashtable instead of a hashmap.
- * </li>
+ * <li>Synchronization aspects are not considered so far. This could be
+ * achieved by using a hashtable instead of a hashmap. </li>
* </ul>
* </p>
- *
- * @see ConsumerRegistry
- *
+ *
+ * @see ConsumerRegistry
+ *
* @version $Id$
*/
-public class ConsumerRegistryImpl implements ConsumerRegistry {
-
- private static final Log log =
- LogFactory.getLog(ConsumerRegistryImpl.class);
-
- //initialized handle generator factory
- private HandleGeneratorFactoryImpl genFactory;
- //initialized handle factory
+public class ConsumerRegistryImpl implements ConsumerRegistry
+{
+
+ /**
+ * Logger
+ */
+ private static final Log LOG = LogFactory.getLog( ConsumerRegistryImpl.class );
+
+ /**
+ * HandleGenerator used to create registration handles.
+ */
private HandleGenerator generator;
-
- //persistence
+
+ // persistence
private PersistentDataObject persistentDataObject;
- //container for stored objects (information+data)
- private PersistentHandler persistentHandler;
- //generic persistence mechansim (store/restore)
-
- //indicates whether the consumer requires registration
+
+ // container for stored objects (information+data)
+ private PersistentHandler persistentHandler;
+
+ /**
+ * Indicates if the portlet requires registration. Obtained
+ * from the ServiceDescription.
+ */
private boolean requiresRegistration = false;
-
- //holds the actual consumer information
+
+ /**
+ * Map of String registration handles to Registration objects.
+ */
private Map registrations;
-
-
+
/**
- * Private constructor of ConsumerRegistryImpl.
- * @param provider a Provider
+ * Constructs a Consumer Registry.
+ *
+ * @param HandleGenerator
+ * @param ProducerPersistentFactory
+ * @param DescriptionHandler
+ *
+ * @throws IllegalArgumentException if any of the arguments are null
+ * @throws WSRPException
*/
- private ConsumerRegistryImpl(Provider provider) throws WSRPException {
-
- super();
-
- String MN = "ConsumerRegistryImpl";
-
- if (log.isDebugEnabled()) {
- log.debug(Utility.strEnter(MN));
+ public ConsumerRegistryImpl( HandleGenerator handleGenerator, ProducerPersistentFactory persistenceFactory,
+ DescriptionHandler descriptionHandler ) throws WSRPException
+ {
+
+ if ( handleGenerator == null )
+ {
+ final String msg = "Handle generator must not be null";
+ LOG.error( msg );
+ throw new IllegalArgumentException( msg );
+ }
+
+ if ( persistenceFactory == null )
+ {
+ final String msg = "Persistence factory must not be null";
+ LOG.error( msg );
+ throw new IllegalArgumentException( msg );
+ }
+
+ if ( descriptionHandler == null )
+ {
+ final String msg = "Description handler must not be null";
+ LOG.error( msg );
+ throw new IllegalArgumentException( msg );
}
-
- if (provider != null) {
-
- DescriptionHandler descrHandler = null;
- if ((descrHandler = provider.getDescriptionHandler()) != null) {
- requiresRegistration = descrHandler.isRegistrationRequired();
- }
- }
-
- genFactory = new HandleGeneratorFactoryImpl();
- generator = genFactory.getHandleGenerator();
-
+ requiresRegistration = descriptionHandler.isRegistrationRequired();
+ generator = handleGenerator;
registrations = new HashMap();
-
+
// restore registration objects from persistent file store
-
- try {
- ProducerPersistentFactory persistentFactory =
- PersistentAccess.getProducerPersistentFactory();
- persistentHandler = persistentFactory.getPersistentHandler();
- persistentDataObject = persistentFactory.getRegistrationList();
-
+
+ try
+ {
+ persistentHandler = persistenceFactory.getPersistentHandler();
+ persistentDataObject = persistenceFactory.getRegistrationList();
restore();
- } catch (Exception e) {
-
- // write warning to log
- if (log.isWarnEnabled()) {
- log.warn("Could not restore all registered consumers. " +
- "Check persistent store.");
- }
}
-
- if (log.isDebugEnabled()) {
- log.debug("ConsumerRegistry successfully constructed.");
+ catch ( Exception e )
+ {
+ LOG.warn( "Could not restore all registered consumers. Check persistent store." );
}
-
- if (log.isDebugEnabled()) {
- log.debug(Utility.strExit(MN));
+
+ if ( LOG.isDebugEnabled() )
+ {
+ LOG.debug( "ConsumerRegistry successfully constructed." );
}
-
}
-
- /**
- * Creates a new ConsumerRegistryImpl-object. To be called within
- * an implementation of the abstract factory ConsumerRegistryFactory.
- * @param provider the provider interface
- */
- public static ConsumerRegistryImpl create(Provider provider)
- throws WSRPException {
- return new ConsumerRegistryImpl(provider);
- }
-
+
/**
- * Provides information about whether this producer requires
- * registration or not. Queries the DescriptionHandler to figure this out.
- *
+ * Provides information about whether this producer requires registration or
+ * not. Queries the DescriptionHandler to figure this out.
+ *
* @return A boolean indicating whether registration is required or not
*/
- public boolean isRegistrationRequired() {
-
+ public boolean isRegistrationRequired( )
+ {
return this.requiresRegistration;
+ }
+
+ /**
+ * Establishes a registration for the consumer and persists it.
+ *
+ * @param registrationData WSRP RegistrationData
+ * @return Registration the Registration
+ *
+ * @throws WSRPException if the registration cannot be persisted
+ */
+ public Registration register( RegistrationData registrationData ) throws WSRPException
+ {
+ // create the registration context
+ RegistrationContext rctx = new RegistrationContext();
+ rctx.setRegistrationHandle( generator.generateHandle() );
+ rctx.setRegistrationState( null );
+ rctx.setExtensions( null );
+ // create the registration
+ Registration registration = new RegistrationImpl( rctx, registrationData );
+
+ // add new registration to hashmap
+ registrations.put( registration.getRegistrationHandle(), registration );
+
+ // store new registration to persistent file
+ persistentDataObject.clear();
+ persistentDataObject.addObject( registration );
+ try
+ {
+ store( persistentDataObject );
+ }
+ catch ( WSRPException e )
+ {
+ // cleanup on error
+ registrations.remove( registration.getRegistrationHandle() );
+ throw e;
+ }
+
+ if ( LOG.isDebugEnabled() )
+ {
+ LOG.debug( "Established registration with handle [" + registration.getRegistrationHandle() + "]" +
+ "for consumer [" + registrationData.getConsumerName() + "]" );
+ }
+
+ return registration;
}
/**
- * Creates a new registration-object for a certain consumer,
- * adds it to the hashmap and returns it.
- *
- * @param registrationData RegistrationData-object
- *
- * @return Registration Registration-object
- *
- * @throws WSRPException
+ * Modifies the Registration for the supplied registration handle. If the registrationHandle
+ * does not refer to an existing handle, this method returns null. Otherwise, the supplied
+ * Registration replaces the old Registration, and the new Registration is persisted.
+ *
+ * @throws WSRPException if persisting the new Registration fails
*/
- public Registration register(RegistrationData registrationData)
- throws WSRPException {
-
- String MN = "register";
-
- if (log.isDebugEnabled()) {
- log.debug(Utility.strEnter(MN));
+ public void modify( String registrationHandle, Registration registration ) throws WSRPException
+ {
+ if (! registrations.containsKey( registrationHandle ) )
+ {
+ return;
}
- Registration newRegistration = new RegistrationImpl();
-
- RegistrationContext newContext = new RegistrationContext();
-
- newContext.setRegistrationHandle(generator.generateHandle());
- newContext.setRegistrationState(null);
- newContext.setExtensions(null);
-
- // set RegistrationData, RegistrationContext etc.
- newRegistration.setRegistrationData(registrationData);
- newRegistration.setRegistrationContext(newContext);
-
- // add new registration to hashmap
- registrations.put(newContext.getRegistrationHandle(), newRegistration);
+ registrations.put( registrationHandle, registration );
// store new registration to persistent file
persistentDataObject.clear();
- persistentDataObject.addObject(newRegistration);
- try {
-
- store(persistentDataObject);
-
- } catch (WSRPException e) {
+ persistentDataObject.addObject( registration );
+ try
+ {
+ store( persistentDataObject );
+ }
+ catch ( WSRPException e )
+ {
// cleanup on error
- registrations.remove(newContext.getRegistrationHandle());
-
+ registrations.remove( registration.getRegistrationHandle() );
throw e;
}
-
- if (log.isDebugEnabled()) {
- log.debug("Consumer with registration handle: " +
- newContext.getRegistrationHandle() + " is registered");
- }
-
- if (log.isDebugEnabled()) {
- log.debug(Utility.strExit(MN));
+
+ if ( LOG.isDebugEnabled() )
+ {
+ LOG.debug( "Modified consumer registration handle[" + registration.getRegistrationHandle() + "] " +
+ "for consumer [" + registration.getRegistrationData().getConsumerName() + "]" );
}
-
- return newRegistration;
}
-
+
/**
* Returns a certain registration identified by regHandle.
- *
- * @param regHandle String representing the regHandle.
- *
+ *
+ * @param regHandle
+ * String representing the regHandle.
+ *
* @return Registration Registration-object identified by regHandle.
*/
- public Registration get(String regHandle) {
- return (Registration)registrations.get(regHandle);
+ public Registration get( String regHandle )
+ {
+ return (Registration) registrations.get( regHandle );
}
-
+
/**
- * Returns all registrations (of all consumers) currently stored
- * in the hashmap.
- *
+ * Returns all registrations (of all consumers) currently stored in the
+ * hashmap.
+ *
* @return Iterator of an registration collection containing all
* registrations.
*/
- public Iterator getAll() {
+ public Iterator getAll( )
+ {
return registrations.values().iterator();
}
-
+
/**
* Deletes the registration of a certain consumer (identified by regHandle)
* from the hashmap.
- *
- * @param regHandle String representing the regHandle.
+ *
+ * @param regHandle
+ * String representing the regHandle.
*/
- public void deregister(String regHandle) {
-
- String MN = "deregister";
-
- if (log.isDebugEnabled()) {
- log.debug(Utility.strEnter(MN));
- }
-
- try {
+ public void deregister( String regHandle )
+ {
+
+ try
+ {
persistentDataObject.clear();
- persistentDataObject.addObject(registrations.get(regHandle));
- delete(persistentDataObject);
- registrations.remove(regHandle);
-
- if (log.isDebugEnabled()) {
- log.debug("Consumer with registration handle: " +
- regHandle + " is now deregistered.");
- }
- } catch (WSRPException e) {
- if (log.isErrorEnabled()) {
- log.error("Error while deregistering consumer with " +
- "handle: " + regHandle, e);
+ persistentDataObject.addObject( registrations.get( regHandle ) );
+ delete( persistentDataObject );
+ registrations.remove( regHandle );
+
+ if ( LOG.isDebugEnabled() )
+ {
+ LOG.debug( "Consumer with registration handle: " + regHandle + " is now deregistered." );
}
}
-
- if (log.isDebugEnabled()) {
- log.debug(Utility.strExit(MN));
+ catch ( WSRPException e )
+ {
+ if ( LOG.isErrorEnabled() )
+ {
+ LOG.error( "Error while deregistering consumer with handle: " + regHandle, e );
+ }
}
}
-
+
/**
- * Evaluates whether a registration with regHandle exists or not.
- * Returns true if registration exists, else false.
- *
- * @param regHandle String representing the regHandle.
- *
+ * Evaluates whether a registration with regHandle exists or not. Returns
+ * true if registration exists, else false.
+ *
+ * @param regHandle
+ * String representing the regHandle.
+ *
* @return Returns true if registration exists, else false.
*/
- public boolean check(String regHandle) {
-
- String MN = "check";
-
- if (log.isDebugEnabled()) {
- log.debug(Utility.strEnter(MN));
- }
-
+ public boolean check( String regHandle )
+ {
// check registration
boolean regExists = false;
- if (registrations.get(regHandle) != null) {
+ if ( registrations.get( regHandle ) != null )
+ {
regExists = true;
-
- if (log.isDebugEnabled()) {
- log.debug("Consumer with registration handle: " +
- regHandle + " is registered.");
+
+ if ( LOG.isDebugEnabled() )
+ {
+ LOG.debug( "Consumer with registration handle: " + regHandle + " is registered." );
}
}
-
- if (log.isDebugEnabled()) {
- log.debug(Utility.strExit(MN));
- }
-
+
return regExists;
}
-
+
/**
* Store the given Registration to persistent store
- *
+ *
* @param persistentDataObject
*/
- private void store(PersistentDataObject persistentDataObject)
- throws WSRPException {
-
- String MN = "store";
-
- if (log.isDebugEnabled()) {
- log.debug(Utility.strEnter(MN));
- }
-
+ private void store( PersistentDataObject persistentDataObject ) throws WSRPException
+ {
// store single object
- persistentHandler.store(persistentDataObject);
-
- if (log.isDebugEnabled()) {
- log.debug(Utility.strExit(MN));
- }
-
+ persistentHandler.store( persistentDataObject );
}
-
+
/**
* Restore all registrations from persistent store
*/
- private void restore() throws WSRPException {
-
- String MN = "restore";
-
- if (log.isDebugEnabled()) {
- log.debug(Utility.strEnter(MN));
- }
-
+ private void restore( ) throws WSRPException
+ {
// clear the collection
registrations.clear();
-
- try {
- persistentDataObject =
- persistentHandler.restoreMultiple(persistentDataObject);
+
+ try
+ {
+ persistentDataObject = persistentHandler.restoreMultiple( persistentDataObject );
Iterator iterator = persistentDataObject.getObjects();
-
- while (iterator.hasNext()) {
- Registration reg = (Registration)iterator.next();
- registrations.put(
- reg.getRegistrationContext().getRegistrationHandle(),
- reg);
+
+ while ( iterator.hasNext() )
+ {
+ Registration reg = (Registration) iterator.next();
+ registrations.put( reg.getRegistrationHandle(), reg );
}
- } catch (WSRPException e) {
-
+ }
+ catch ( WSRPException e )
+ {
// cleanup on error
registrations.clear();
-
throw e;
}
-
- if (log.isDebugEnabled()) {
- log.debug(Utility.strExit(MN));
- }
-
}
-
+
/**
* Delete the given Registration from persistent store
- *
+ *
* @param persistentDataObject
*/
- private void delete(PersistentDataObject persistentDataObject)
- throws WSRPException {
-
- String MN = "delete";
-
- if (log.isDebugEnabled()) {
- log.debug(Utility.strEnter(MN));
- }
+ private void delete( PersistentDataObject persistentDataObject ) throws WSRPException
+ {
// delete object
- persistentHandler.delete(persistentDataObject);
-
- if (log.isDebugEnabled()) {
- log.debug(Utility.strExit(MN));
- }
-
+ persistentHandler.delete( persistentDataObject );
}
-
+
}