Return-Path: Delivered-To: apmail-jakarta-avalon-cvs-archive@apache.org Received: (qmail 76992 invoked from network); 9 Sep 2002 13:44:59 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 9 Sep 2002 13:44:58 -0000 Received: (qmail 10964 invoked by uid 97); 9 Sep 2002 13:45:32 -0000 Delivered-To: qmlist-jakarta-archive-avalon-cvs@jakarta.apache.org Received: (qmail 10894 invoked by uid 97); 9 Sep 2002 13:45:32 -0000 Mailing-List: contact avalon-cvs-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list avalon-cvs@jakarta.apache.org Received: (qmail 10883 invoked by uid 97); 9 Sep 2002 13:45:31 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Date: 9 Sep 2002 13:44:53 -0000 Message-ID: <20020909134453.57847.qmail@icarus.apache.org> From: mcconnell@apache.org To: jakarta-avalon-excalibur-cvs@apache.org Subject: cvs commit: jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/service DefaultRegistry.java Registry.java DefaultServiceManagementContext.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N mcconnell 2002/09/09 06:44:53 Added: assembly/src/java/org/apache/excalibur/merlin/activation Directory.java Directory.xinfo assembly/src/java/org/apache/excalibur/merlin/service DefaultRegistry.java Registry.java Removed: assembly/src/java/org/apache/excalibur/merlin/activation DefaultServiceResolver.java DefaultServiceResolver.xinfo assembly/src/java/org/apache/excalibur/merlin/service DefaultServiceManagementContext.java Log: Class name rationalization and service and activation packages. Revision Changes Path 1.1 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/activation/Directory.java Index: Directory.java =================================================================== package org.apache.excalibur.merlin.activation; import java.io.Serializable; import java.net.URL; import java.net.MalformedURLException; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.service.Serviceable; import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.activity.Startable; import org.apache.avalon.framework.activity.Disposable; import org.apache.orb.ORB; import org.apache.orb.corbaloc.InvalidQuery; import org.apache.orb.corbaloc.ServiceRedirection; import org.apache.orb.corbaloc.UnknownReference; import org.apache.orb.corbaloc.InvalidReference; import org.apache.orb.corbaloc.Handler; import org.apache.orb.corbaloc.Resolver; import org.apache.orb.corbaloc.ServiceResolver; import org.apache.orb.corbaloc.ServiceResolverOperations; import org.apache.orb.corbaloc.ServiceResolverPOATie; import org.apache.orb.corbaloc.ServiceResolverHelper; import org.openorb.corbaloc.CorbalocService; import org.openorb.corbaloc.CorbalocServiceHelper; import org.apache.excalibur.merlin.assembly.ContainerManager; import org.apache.excalibur.merlin.container.Container; import org.apache.excalibur.merlin.container.DefaultContainer; import org.apache.excalibur.merlin.service.Registry; import org.apache.excalibur.merlin.service.UnknownServiceException; import org.apache.excalibur.merlin.service.InvalidPathException; import org.apache.excalibur.merlin.model.Resource; import org.omg.CORBA.Any; import org.omg.PortableServer.POA; import org.omg.PortableServer.Servant; import org.omg.PortableServer.IdAssignmentPolicyValue; import org.omg.PortableServer.LifespanPolicyValue; import org.omg.CORBA.Policy; /** * Implementation of a container that provides support for remotely * accessible services. Services managed by this container my be * accessed using a corbaloc URL. The implemetation handles the management * of incomming requests by redirecting requests to servant implementation * exposing remotely accessible services. * * @author Stephen McConnell */ public class Directory extends DefaultContainer implements ServiceResolverOperations, Serviceable, Startable, Disposable { /** * The service manager from which we aquire the ORB. */ private ServiceManager m_services; /** * The context from which we access the component name. */ private Context m_context; /** * The server ORB used to locate the corbaloc service, POA service, and * handle POA activation. */ private ORB m_orb; /** * The root POA. */ private POA m_root; /** * The POA for this servant. */ private POA m_poa; /** * Internal reference to the object reference to this server. */ private ServiceResolver m_resolver; /** * The name of this server. */ private String m_name; /** * The URL that this container is published under. */ private URL m_corbaloc; /** * The container's resource registry. */ private Registry m_registry; //================================================================= // Contextualizable //================================================================= /** * Method invoked by the ORB initializer to declare the runtime context. * @param context runtime application context * @exception ContextException if the supplied context does not meet * contextulization criteria */ public void contextualize( Context context ) throws ContextException { super.contextualize( context ); m_name = (String) context.get("avalon:name"); m_registry = (Registry) context.get( REGISTRY_KEY ); m_context = context; } //======================================================================= // Serviceable //======================================================================= /** * Method invoked by the container to provide dependent services. * @param manager the service manager */ public void service( final ServiceManager manager ) { m_services = manager; } //======================================================================= // Initializable //======================================================================= /** * Initialization of the server. The initialization validates that a * logging channel is available, that configuration exists, and that * context is not null. Following validation, the implementation * creates an ORB based on a child configuration named 'orb' supplied * during Initializer establishment. Once the ORB is obtained, the * implementation handles the establishment of the POA and servant. * * @exception Exception if initialization fails */ public void initialize() throws Exception { super.initialize(); // // get the POA // m_orb = (ORB) m_services.lookup("orb"); m_root = (POA) m_orb.resolve_initial_references("RootPOA"); CorbalocService registry = CorbalocServiceHelper.narrow( m_orb.resolve_initial_references( "CorbalocService" ) ); final String key = m_name; try { m_poa = m_root.create_POA( key, m_root.the_POAManager(), new Policy[] { m_root.create_id_assignment_policy( IdAssignmentPolicyValue.USER_ID ), m_root.create_lifespan_policy( LifespanPolicyValue.PERSISTENT ) } ); Servant servant = new ServiceResolverPOATie( this ); byte[] id = key.getBytes(); m_poa.activate_object_with_id( id, servant ); m_resolver = ServiceResolverHelper.narrow( m_poa.id_to_reference( id ) ); } catch( Throwable e ) { String error = "Unable to create the application POA: " + e.toString(); throw new ActivationException( error, e ); } String path = registry.put_object( m_resolver, key ); m_corbaloc = new URL( null, path, new Handler( m_orb ) ); getLogger().info("remote: " + m_corbaloc ); } //======================================================================= // Startable //======================================================================= /** * Start the container. * @exception Exception if a startup error occurs */ public void start() throws Exception { m_poa.the_POAManager().activate(); super.start(); } /** * Stops the container. * @exception Exception if a shutdown error occurs */ public void stop() throws Exception { try { m_poa.destroy( true, true ); } catch( Throwable e ) { if( getLogger().isWarnEnabled() ) { getLogger().warn( "ignoring POA related exception" ); } } super.stop(); } //======================================================================= // corbaloc::Resolver //======================================================================= /** * Process a corbaloc request. * * @param path a path relative to this container * @return an object reference * @exception InvalidQuery if the supplied path is invalid * @exception ServiceRedirection if the ref resolution is being redirected */ public org.omg.CORBA.Object resolve( String path ) throws InvalidQuery, ServiceRedirection, UnknownReference, InvalidReference { // // check if this is a reference to ourselves // if( path.equals("") ) { // // the URI is refering to ourselves // return m_resolver; } // // It is a path refering to a contained resource (container or service). // Use the registry to locate the resource and if the resource is a referencable // resource then get and return the refence. // try { Resource resource = m_registry.locate( path ); getLogger().debug("located a resource: " + resource ); // // we have located a resource matching the resolved uri // so we need to verify if the object type backing the resource // can be passed back to the client inside an any // if( resource instanceof RemoteResource ) { return ((RemoteResource)resource).getReference(); } } catch( UnknownServiceException use ) { throw new UnknownReference( path, use.getMessage() ); } catch( InvalidPathException ipe ) { throw new InvalidReference( path, ipe.getMessage() ); } final String error = "Supplied path is a local service."; throw new InvalidReference( path, error ); } //======================================================================= // Disposable //======================================================================= /** * Disposal of the server. This method is triggered by a shutdown hook * becuase initializers are not cleared by an ORB on shutdown. */ public void dispose() { super.dispose(); } //======================================================================= // implementation //======================================================================= /** * Pack a value in an. * @param any the Any * @return Object the any contents as a Java Object */ private Any putResult( Any any, Object object ) { if( any == null ) { throw new NullPointerException("any"); } if( object == null ) { throw new NullPointerException("object"); } if( object instanceof org.omg.CORBA.Object ) { any.insert_Object( (org.omg.CORBA.Object) object ); return any; } else if( object instanceof Serializable ) { any.insert_Value((Serializable) object ); return any; } else { throw new IllegalStateException( "Object type: " + any.type().kind().value() + " unsupported."); } } } 1.1 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/activation/Directory.xinfo Index: Directory.xinfo =================================================================== activator orb 1.1 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/service/DefaultRegistry.java Index: DefaultRegistry.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.excalibur.merlin.service; import java.net.URL; import java.net.MalformedURLException; import java.util.Map; import java.util.Hashtable; import java.util.Iterator; import org.apache.excalibur.merlin.model.Resource; /** * Default implementation of a service management context. * * @author Stephen McConnell * @version $Revision: 1.1 $ $Date: 2002/09/09 13:44:53 $ */ public class DefaultRegistry implements Registry { //============================================================= // state //============================================================= /** * The context url. */ private URL m_base; /** * A map of child naming context entries keyed by context name. */ private Map m_table = new Hashtable(); /** * The parent naming context. */ private Registry m_parent; /** * A hashtable of resources keyed by service name. */ private Map m_children = new Hashtable(); //============================================================= // constructor //============================================================= /** * Creation of a new service management context. The implementation * handles the once only establishment of the service URL protocol * handler and registers this instance as the root of the service * management naming context hierachy. * * @param domain the host domain name * @exception NullPointerException if the supplied domain name is null * @exception MalformedURLException if the supplied domain name is inconsistent */ public DefaultRegistry( final String domain ) throws NullPointerException, MalformedURLException { if( domain == null ) { throw new NullPointerException( "domain" ); } URL.setURLStreamHandlerFactory( new ServiceURLFactory( domain, this ) ); m_base = new URL("service", domain, -1, "/"); } /** * Creation of a new service management context. * * @param parent the parent context * @param name the context name * @exception NullPointerException if the supplied name or parent is null */ public DefaultRegistry( final Registry parent, final String name ) throws NullPointerException, MalformedURLException { if( name == null ) { throw new NullPointerException( "name" ); } if( parent == null ) { throw new NullPointerException( "parent" ); } m_parent = parent; URL base = m_parent.getBase(); String path = base.getPath(); if( name.endsWith("/") ) { m_base = new URL( base, path + name ); } else { m_base = new URL( base, path + name + "/" ); } } //============================================================= // Registry //============================================================= /** * Returns the base context URL. * * @return the context url */ public URL getBase() { return m_base; } /** * Creation of a subsidiary service context. * * @param name the relative name * @return the service context object * @exception NullPointerException if the supplied name is null * @exception MalformedURLException if the name is invalid * @exception IllegalArgumentException if the name is already in use */ public Registry createChild( String name ) throws MalformedURLException, IllegalArgumentException { if( name == null ) { throw new NullPointerException("name"); } if( m_children.get( name ) != null ) { final String error = "Duplicate name: " + name; throw new IllegalArgumentException( error ); } Registry context = new DefaultRegistry( this, name ); m_children.put( name, context ); return context; } /** * Bind a resource to the naming context. * * @exception IllegalArgumentException if the supplied resource * name already exists within the immediate context */ public void bind( Resource resource ) { final String name = resource.getProfile().getName(); if( m_table.get( name ) != null ) { final String error = "Duplicate name: " + name; throw new IllegalArgumentException( error ); } m_table.put( name, resource ); } /** * Unbind a resource from the naming context. * * @exception IllegalArgumentException if the supplied resource is * unknown within the immediate scope of the context */ public void unbind( Resource resource ) { String name = resource.getProfile().getName(); Iterator iterator = m_table.entrySet().iterator(); while( iterator.hasNext() ) { Resource res = (Resource) iterator.next(); if( res.getProfile().getName().equals( name ) ) { m_table.remove( name ); break; } } final String error = "Unknown resource: " + name; throw new IllegalArgumentException( error ); } /** * Select a set of service based on a supplied filter. A filter is * supplied in the form of a URI String. Interpritation relative to URI path, query, * and fragment are protocol dependent. * * @param uri the service uri * @exception Exception is an install error occurs */ public Resource locate( String uri ) throws UnknownServiceException, InvalidPathException { if( uri.indexOf("/") > -1 ) { String name = uri.substring( 0, uri.indexOf("/") ); Registry child = (Registry) m_children.get( name ); if( child != null ) { return child.locate( uri.substring( uri.indexOf("/") + 1, uri.length() ) ); } else { final String error = "Invalid path element: " + name; throw new InvalidPathException( uri, error ); } } else { // // its an immediate resource // Registry child = (Registry) m_children.get( uri ); if( child != null ) { // // then forward the request to the child context // return child.locate(""); } else { Resource resource = (Resource) m_table.get( uri ); if( resource != null ) { return resource; } final String error = "Could not locate the requested service."; throw new UnknownServiceException( uri, error ); } } } } 1.1 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/service/Registry.java Index: Registry.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.excalibur.merlin.service; import java.net.URL; import java.net.MalformedURLException; import org.apache.excalibur.merlin.model.Resource; /** * Interface used to register an established service. * * @author Stephen McConnell * @version $Revision: 1.1 $ $Date: 2002/09/09 13:44:53 $ */ public interface Registry { /** * Returns the base context URL. * * @return the context url */ public URL getBase(); /** * Creation of a subsidiary service context. * * @param name the relative name * @return the service context object * @exception MalformedURLException if the name is invalid * @exception IllegalArgumentException if the name is already in use */ public Registry createChild( String name ) throws MalformedURLException, IllegalArgumentException; /** * Bind a resource to the naming context. * @param resource the resource */ public void bind( Resource resource ); /** * Unbind a resource from the naming context. * @param resource the resource */ public void unbind( Resource resource ); /** * Select a set of service based on a supplied filter. A filter is * supplied in the form of a String. Interpritation of string follows * normal URI semantics (path, query, and reference elements are protocol * dependent). * * @param uri the service uri * @exception Exception is an install error occurs */ Resource locate( String uri ) throws UnknownServiceException, InvalidPathException; } -- To unsubscribe, e-mail: For additional commands, e-mail: