You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by ni...@apache.org on 2008/12/10 06:15:49 UTC
svn commit: r724983 [3/4] - in
/incubator/river/jtsk/skunk/niclas1/services/start: ./ src/ src/main/
src/main/java/ src/main/java/com/ src/main/java/com/sun/
src/main/java/com/sun/jini/ src/main/java/com/sun/jini/start/
src/main/java/com/sun/jini/start...
Added: incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedActivatableServiceDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedActivatableServiceDescriptor.java?rev=724983&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedActivatableServiceDescriptor.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedActivatableServiceDescriptor.java Tue Dec 9 21:15:48 2008
@@ -0,0 +1,776 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.sun.jini.start;
+
+import com.sun.jini.config.Config;
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamException;
+import java.rmi.MarshalledObject;
+import java.rmi.activation.ActivationException;
+import java.rmi.activation.ActivationGroupID;
+import java.rmi.activation.ActivationID;
+import java.rmi.activation.ActivationSystem;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import net.jini.config.Configuration;
+import net.jini.security.BasicProxyPreparer;
+import net.jini.security.ProxyPreparer;
+
+/**
+ * Class used to launch shared, activatable services.
+ * Clients construct this object with the details
+ * of the service to be launched, then call
+ * {@link #create(net.jini.config.Configuration) create(Configuration config) }
+ * to launch the service in an existing
+ * {@linkplain SharedActivationGroupDescriptor shared activation group}
+ * identified by the <code>sharedGroupLog</code> constructor parameter.
+ * <P>
+ * This class depends on {@link ActivateWrapper} to provide
+ * separation of the import codebase
+ * (where the service implementation classes are loaded from)
+ * from the export codebase
+ * (where service clients should load classes from, for example stubs)
+ * as well as providing an independent security policy file for each
+ * service object. This functionality allows multiple service objects
+ * to be placed in the same activation system group, with each object
+ * maintaining distinct export codebase and security policy settings.
+ * <P>
+ * Services need to implement the "activatable"
+ * <A HREF="ActivateWrapper.html#serviceConstructor">constructor</A>
+ * required by {@link ActivateWrapper}.
+ * <P>
+ * <A NAME="serviceProxy"></A>
+ * A service implementation
+ * can return its service proxy (via the <code>proxy</code> field of the
+ * {@link Created Created} object returned
+ * by {@link #create(net.jini.config.Configuration) create})
+ * in the following ways:
+ * <DL>
+ * <DT><A NAME="innerProxy">Return Inner Proxy</A></DT>
+ * <DD><P>
+ * The service's inner proxy is the
+ * {@link java.rmi.Remote} object returned from
+ * {@link java.rmi.activation.ActivationID#activate(boolean)} using
+ * {@link ActivateWrapper} to "wrap" and register the desired service
+ * with the activation system.
+ * A "wrapped" service's inner proxy is returned as follows:
+ *
+ * <UL>
+ * <LI>If the newly created service instance implements {@link
+ * net.jini.export.ProxyAccessor}, a proxy is obtained by invoking the {@link
+ * net.jini.export.ProxyAccessor#getProxy getProxy} method on that instance. If the
+ * obtained proxy is not <code>null</code>, that proxy is returned in a
+ * {@link java.rmi.MarshalledObject}; otherwise, an
+ * {@link java.io.InvalidObjectException} is thrown.
+ *
+ * <LI>If the newly created instance does not implement
+ * {@link net.jini.export.ProxyAccessor}, the instance is returned in a
+ * {@link java.rmi.MarshalledObject}. In this case, the instance must be
+ * serializable, and marshalling the instance must produce a suitable
+ * proxy for the remote object (for example, the object implements
+ * {@link java.io.Serializable} and defines a <code>writeReplace</code>
+ * method that returns the object's proxy).
+ * </UL>
+ *
+ * <P></DD>
+ * <DT><A NAME="outerProxy">Return Outer Proxy</A></DT>
+ * <DD><P>
+ * The service's outer proxy is the object returned from invoking
+ * {@link ServiceProxyAccessor#getServiceProxy()} on
+ * the service's <A HREF="#innerProxy">inner proxy</A>.
+ * <P></DD>
+ * </DL>
+ *
+ * The following items are discussed below:
+ * <ul>
+ * <li><a href="#configEntries">Configuring SharedActivatableServiceDescriptor</a>
+ * <li><a href="#logging">Logging</a>
+ * </ul>
+ *
+ * <a name="configEntries">
+ * <h3>Configuring SharedActivatableServiceDescriptor</h3>
+ * </a>
+ *
+ * <code>SharedActivatableServiceDescriptor</code>
+ * depends on {@link ActivateWrapper}, which can itself be configured. See
+ * {@linkplain ActivateWrapper}'s
+ * <A HREF="ActivateWrapper.html#configEntries">configuration</A>
+ * information for details.
+ * <p>
+ * This implementation obtains its configuration entries from the
+ * {@link net.jini.config.Configuration Configuration} object passed into
+ * the {@link #create(net.jini.config.Configuration) create} method.
+ * The following configuration entries use the
+ * component prefix "<code>com.sun.jini.start</code>":
+ * <p>
+ *
+ * <table summary="Describes the activationIdPreparer configuration entry"
+ * border="0" cellpadding="2">
+ * <tr valign="top">
+ * <th scope="col" summary="layout"> <font size="+1">•</font>
+ * <th scope="col" align="left" colspan="2"> <font size="+1"><code>
+ * activationIdPreparer</code></font>
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Type: <td> {@link net.jini.security.ProxyPreparer}
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Default: <td> <code>
+ * new {@link net.jini.security.BasicProxyPreparer}()
+ * </code>
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Description: <td> The proxy preparer for the service's activation
+ * ID. The value should not be <code>null</code>.
+ *
+ * This class calls the
+ * {@link java.rmi.activation.ActivationID#activate
+ * activate} method on instances of {@link
+ * java.rmi.activation.ActivationID} when they need to re/activate the
+ * service.
+ * </table>
+ *
+ * <table summary="Describes the activationSystemPreparer configuration
+ * entry"
+ * border="0" cellpadding="2">
+ * <tr valign="top">
+ * <th scope="col" summary="layout"> <font size="+1">•</font>
+ * <th scope="col" align="left" colspan="2"> <font size="+1"><code>
+ * activationSystemPreparer</code></font>
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Type: <td> {@link net.jini.security.ProxyPreparer}
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Default: <td> <code>
+ * new {@link net.jini.security.BasicProxyPreparer}()</code>
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Description: <td> The proxy preparer for the proxy for the
+ * activation system. The value should not be <code>null</code>.
+ *
+ * The service starter calls the {@link
+ * java.rmi.activation.ActivationSystem#unregisterObject
+ * unregisterObject} method on the {@link
+ * java.rmi.activation.ActivationSystem} when there is a problem
+ * creating a service.
+ * </table>
+ *
+ * <a name="servicePreparer">
+ * <table summary="Describes the default service preparer configuration entry"
+ * border="0" cellpadding="2">
+ * <tr valign="top">
+ * <th scope="col" summary="layout"> <font size="+1">•</font>
+ * <th scope="col" align="left" colspan="2"> <font size="+1"><code>
+ * servicePreparer</code></font>
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Type: <td> {@link net.jini.security.ProxyPreparer}
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Default: <td> <code>
+ * new {@link net.jini.security.BasicProxyPreparer}()
+ * </code>
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Description: <td> The default proxy preparer used to prepare
+ * service proxies.
+ * This value should not be <code>null</code>. This entry is
+ * obtained during the invocation of
+ * {@link #create(net.jini.config.Configuration) create} and is used,
+ * to prepare the <A HREF="#innerProxy">inner</A> and
+ * <A HREF="#outerProxy">outer</A> service proxies returned by
+ * the service implementation
+ * (see <a href="#serviceProxy">service proxy</a> section for details).
+ * This entry is superseded by explicitly passing a
+ * {@link ProxyPreparer ProxyPreparer} to one of the constructors that
+ * accept a {@linkplain ProxyPreparer proxy preparer} argument.
+ * </table>
+ *
+ * <a name="logging">
+ * <h3>Loggers and Logging Levels</h3>
+ * </a>
+ *
+ * The implementation uses the {@link
+ * java.util.logging.Logger}, named
+ * <code>com.sun.jini.start.service.starter</code>.
+ * The following table describes the
+ * type of information logged as well as the levels of information logged.
+ * <p>
+ *
+ * <table border="1" cellpadding="5"
+ * summary="Describes logging performed by the shared,
+ * activatable service descriptor at different
+ * logging levels">
+ *
+ * <caption halign="center" valign="top"><b><code>
+ * com.sun.jini.start.service.starter</code></b></caption>
+ *
+ * <tr> <th scope="col"> Level <th scope="col"> Description
+ *
+ * <tr> <td> {@link java.util.logging.Level#FINER FINER} <td>
+ * for high level
+ * service operation tracing
+ * <tr> <td> {@link java.util.logging.Level#FINEST FINEST} <td>
+ * for low level
+ * service operation tracing
+ *
+ * </table> <p>
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+
+public class SharedActivatableServiceDescriptor
+ extends NonActivatableServiceDescriptor
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @serial <code>String</code> representing the directory where
+ * the associated shared group identifier information is persisted
+ */
+ private final String sharedGroupLog;
+
+ /**
+ * @serial <code>boolean</code> flag passed through as the
+ * <code>restart</code> parameter to the
+ * {@linkplain java.rmi.activation.ActivationDesc#ActivationDesc(java.rmi.activation.ActivationGroupID, java.lang.String, java.lang.String, java.rmi.MarshalledObject, boolean)
+ * ActivationDesc constructor} used to register the service with the
+ * activation system.
+ */
+ private final boolean restart;
+
+ /**
+ * @serial <code>String</code> containing hostname of desired
+ * activation system.
+ */
+ private final String host;
+
+ /**
+ * @serial <code>int</code> representing port of desired activation system.
+ */
+ private final int port;
+
+ private static final Logger logger = ServiceStarter.logger;
+
+ /*
+ * <code>ProxyPreparer</code> reference for preparing the service's proxy
+ * returned from the call to
+ * {@linkplain java.rmi.activation.ActivationID#activate(boolean) activate}.
+ * If this "inner" proxy implements
+ * {@linkplain ServiceProxyAccessor ServiceProxyAccessor} it will then be used to invoke
+ * {@linkplain ServiceProxyAccessor#getServiceProxy() getServiceProxy}.
+ */
+ private /*final*/ transient ProxyPreparer innerProxyPreparer;
+
+ /**
+ * Object returned by
+ * {@link SharedActivatableServiceDescriptor#create(net.jini.config.Configuration)
+ * SharedActivatableServiceDescriptor.create()}
+ * method that returns the associated proxy, activation group
+ * identifier, and activation identifier
+ * for the created service.
+ */
+ public static class Created
+ {
+ /**
+ * The activation group id of the group hosting the service
+ */
+ public final ActivationGroupID gid;
+ /**
+ * The activation id of the service
+ */
+ public final ActivationID aid;
+ /**
+ * The reference to the proxy of the created service
+ */
+ public final Object proxy;
+
+ /**
+ * Constructs an instance of this class.
+ *
+ * @param gid activation group id of the created service
+ * @param aid activation id of the created service
+ * @param proxy reference to the proxy of the created service
+ */
+ public Created( ActivationGroupID gid, ActivationID aid, Object proxy )
+ {
+ this.gid = gid;
+ this.aid = aid;
+ this.proxy = proxy;
+ }//end constructor
+ }//end class Created
+
+
+ /**
+ * Convenience constructor. Equivalent to calling this
+ * {@link #SharedActivatableServiceDescriptor(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String[], net.jini.security.ProxyPreparer, net.jini.security.ProxyPreparer, boolean, java.lang.String, int) constructor}
+ * with the <code>innerProxyPreparer</code>, <code>outerProxyPreparer</code>
+ * and <code>host</code> arguments set to
+ * <code>null</code>
+ * and the <code>port</code> argument set to
+ * the currently configured activation system port.
+ * The activation system port defaults to
+ * {@link ActivationSystem#SYSTEM_PORT} unless it is overridden by the
+ * <code>java.rmi.activation.port</code> system property.
+ */
+ public SharedActivatableServiceDescriptor(
+ // Required Args
+ String exportCodebase,
+ String policy,
+ String importCodebase,
+ String implClassName,
+ String sharedGroupLog,
+ // Optional Args,
+ String[] serverConfigArgs,
+ boolean restart )
+ {
+ this( exportCodebase, policy, importCodebase, implClassName,
+ sharedGroupLog, serverConfigArgs, null,
+ null, restart, null, ServiceStarter.getActivationSystemPort() );
+ }
+
+ /**
+ * Convenience constructor. Equivalent to calling this
+ * {@link #SharedActivatableServiceDescriptor(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String[], net.jini.security.ProxyPreparer, net.jini.security.ProxyPreparer, boolean, java.lang.String, int) constructor}
+ * with the <code>host</code> argument set to
+ * <code>null</code> and the <code>port</code> argument set to the
+ * currently configured activation system port.
+ * The activation system port defaults to
+ * {@link ActivationSystem#SYSTEM_PORT} unless it is overridden by the
+ * <code>java.rmi.activation.port</code> system property.
+ */
+ public SharedActivatableServiceDescriptor(
+ // Required Args
+ String exportCodebase,
+ String policy,
+ String importCodebase,
+ String implClassName,
+ String sharedGroupLog,
+ // Optional Args,
+ String[] serverConfigArgs,
+ ProxyPreparer innerProxyPreparer,
+ ProxyPreparer outerProxyPreparer,
+ boolean restart )
+ {
+ this( exportCodebase, policy, importCodebase, implClassName,
+ sharedGroupLog, serverConfigArgs, innerProxyPreparer,
+ outerProxyPreparer, restart, null, ServiceStarter.getActivationSystemPort() );
+ }
+
+ /**
+ * Convenience constructor. Equivalent to calling this
+ * {@link #SharedActivatableServiceDescriptor(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String[], net.jini.security.ProxyPreparer, net.jini.security.ProxyPreparer, boolean, java.lang.String, int) constructor}
+ * with the <code>innerProxyPreparer</code> and <code>outerProxyPreparer</code> arguments set to
+ * <code>null</code>.
+ */
+ public SharedActivatableServiceDescriptor(
+ // Required Args
+ String exportCodebase,
+ String policy,
+ String importCodebase,
+ String implClassName,
+ String sharedGroupLog,
+ // Optional Args,
+ String[] serverConfigArgs,
+ boolean restart,
+ String host,
+ int port )
+ {
+ this( exportCodebase, policy, importCodebase, implClassName,
+ sharedGroupLog, serverConfigArgs, null, null, restart,
+ host, port );
+ }
+
+ /**
+ * Main constructor. Simply assigns given parameters to
+ * their associated, internal fields unless otherwise noted.
+ *
+ * @param exportCodebase location where clients can download required
+ * service-related classes (for example, stubs, proxies, etc.).
+ * Codebase components must be separated by spaces in which
+ * each component is in <code>URL</code> format.
+ * @param policy server policy filename or URL
+ * @param importCodebase location where server implementation
+ * classes can be found.
+ * This <code>String</code> assumed (in order) to be either
+ * 1) a space delimited set of <code>URL</code>(s)
+ * representing a codebase or
+ * 2) a <code>File.pathSeparator</code> delimited set
+ * of class paths.
+ * @param implClassName name of server implementation class
+ * @param sharedGroupLog location where the associated shared
+ * group identifier information is persisted
+ * @param serverConfigArgs service configuration arguments
+ * @param innerProxyPreparer <code>ProxyPreparer</code> reference. This object
+ * will be used to prepare the service's <A HREF="#innerProxy">inner proxy</A>.
+ * If the inner proxy implements
+ * {@link ServiceProxyAccessor}
+ * it will then be used to invoke
+ * {@link ServiceProxyAccessor#getServiceProxy()} in order to get the
+ * service's <A HREF="#outerProxy">outer proxy</A>.
+ * @param outerProxyPreparer <code>ProxyPreparer</code> reference. This object
+ * will be used to prepare the service's
+ * <A HREF="#outerProxy">outer proxy</A> before it is returned to the caller of
+ * {@link SharedActivatableServiceDescriptor#create(net.jini.config.Configuration)}.
+ * @param restart boolean flag passed through as the
+ * <code>restart</code> parameter to the
+ * {@linkplain java.rmi.activation.ActivationDesc#ActivationDesc(java.rmi.activation.ActivationGroupID, java.lang.String, java.lang.String, java.rmi.MarshalledObject, boolean)
+ * ActivationDesc constructor} used to register the service with the
+ * activation system.
+ * @param host hostname of desired activation system. If <code>null</code>,
+ * defaults to the localhost.
+ * @param port port of desired activation system. If value is <= 0, then
+ * defaults to
+ * {@link java.rmi.activation.ActivationSystem#SYSTEM_PORT
+ * ActivationSystem.SYSTEM_PORT}.
+ */
+ public SharedActivatableServiceDescriptor(
+ // Required Args
+ String exportCodebase,
+ String policy,
+ String importCodebase,
+ String implClassName,
+ String sharedGroupLog,
+ // Optional Args,
+ String[] serverConfigArgs,
+ ProxyPreparer innerProxyPreparer,
+ ProxyPreparer outerProxyPreparer,
+ boolean restart,
+ String host,
+ int port )
+ {
+ super( exportCodebase, policy, importCodebase, implClassName,
+ serverConfigArgs, outerProxyPreparer );
+ if( sharedGroupLog == null )
+ {
+ throw new NullPointerException(
+ "Shared VM log cannot be null" );
+ }
+ this.sharedGroupLog = sharedGroupLog;
+ this.restart = restart;
+ this.host = ( host == null ) ? "" : host;
+ this.port =
+ ( port <= 0 ) ? ServiceStarter.getActivationSystemPort() : port;
+ this.innerProxyPreparer = innerProxyPreparer;
+ }
+
+ /**
+ * Shared group log accessor method.
+ *
+ * @return the Shared group log associated with this service descriptor.
+ */
+ final public String getSharedGroupLog()
+ {
+ return sharedGroupLog;
+ }
+
+ /**
+ * Restart accessor method.
+ *
+ * @return the restart mode associated with this service descriptor.
+ */
+ final public boolean getRestart()
+ {
+ return restart;
+ }
+
+ /**
+ * Activation system host accessor method.
+ *
+ * @return the activation system host associated with
+ * this service descriptor.
+ */
+ final public String getActivationSystemHost()
+ {
+ return host;
+ }
+
+ /**
+ * Activation system port accessor method.
+ *
+ * @return the activation system port associated with this service descriptor.
+ */
+ final public int getActivationSystemPort()
+ {
+ return port;
+ }
+
+ /**
+ * <code>ProxyPreparer</code> accessor method.
+ *
+ * @return the <A HREF="#innerProxy">inner proxy</A> preparer associated with
+ * this service descriptor.
+ */
+ final public ProxyPreparer getInnerProxyPreparer()
+ {
+ return innerProxyPreparer;
+ }
+
+ /**
+ * Sets the <A HREF="#innerProxy">inner</A>
+ * <code>ProxyPreparer</code> for this descriptor.
+ * This needs to
+ * be called on the service descriptor prior to calling
+ * <code>create()</code>. Useful for (re-)setting the
+ * the associated inner <code>ProxyPreparer</code> upon deserialization of
+ * the descriptor.
+ *
+ * @param pp The inner <code>ProxyPreparer</code> object to be
+ * associated with this service descriptor.
+ * @throws IllegalStateException if called after <code>create()</code> is invoked
+ */
+ final public void setInnerProxyPreparer( ProxyPreparer pp )
+ {
+ synchronized( descCreatedLock )
+ {
+ if( descCreated )
+ {
+ throw new IllegalStateException( "Can't set ProxyPreparer after descriptor creation" );
+ }
+ else
+ {
+ innerProxyPreparer = pp;
+ }
+ }
+ }
+
+ /**
+ * Method that attempts to create a service based on the service
+ * description information provided via constructor parameters.
+ * <P>
+ * This method:
+ * <UL>
+ * <LI> creates an <code>ActivateWrapper.ActivateDesc</code> with
+ * the provided constructor parameter information for the
+ * desired service
+ * <LI> retrieves the
+ * {@linkplain java.rmi.activation.ActivationGroupID group identifier}
+ * associated with the provided shared group log.
+ * <LI> invokes
+ * {@link ActivateWrapper#register(java.rmi.activation.ActivationGroupID, com.sun.jini.start.ActivateWrapper.ActivateDesc, boolean, java.rmi.activation.ActivationSystem)
+ * ActivateWrapper.register()} with the provided information.
+ * <LI> obtains an <A HREF="#innerProxy">inner proxy</A> by calling
+ * {@link java.rmi.activation.ActivationID#activate(boolean)
+ * activate(true)} on the object returned from
+ * <code>ActivateWrapper.register()</code>, which also
+ * activates the service instance.
+ * <LI> obtains the service proxy in the following
+ * order of precedence:
+ * <UL>
+ * <LI>if the <A HREF="#innerProxy">inner proxy</A> implements
+ * {@link ServiceProxyAccessor} then the return value of
+ * {@link ServiceProxyAccessor#getServiceProxy() getServiceProxy}
+ * is used
+ * <LI>if the <A HREF="#innerProxy">inner proxy</A> is
+ * not <code>null</code> then it is used
+ * <LI>Otherwise, <code>null</code> is used
+ * </UL>
+ *
+ * @return a
+ * {@link com.sun.jini.start.SharedActivatableServiceDescriptor.Created
+ * Created} object that contains the group identifier, activation ID, and
+ * proxy associated with the newly created service instance.
+ * @throws java.lang.Exception Thrown if there was any problem
+ * creating the object.
+ */
+ public Object create( Configuration config ) throws Exception
+ {
+ ServiceStarter.ensureSecurityManager();
+ logger.entering( SharedActivatableServiceDescriptor.class.getName(),
+ "create", new Object[]{ config } );
+
+ if( config == null )
+ {
+ throw new NullPointerException(
+ "Configuration argument cannot be null" );
+ }
+
+ ProxyPreparer globalServicePreparer =
+ (ProxyPreparer) Config.getNonNullEntry( config,
+ ServiceStarter.START_PACKAGE,
+ "servicePreparer", ProxyPreparer.class,
+ new BasicProxyPreparer() );
+
+ // Needs to be called prior to setting the "descCreated" flag
+ if( getServicePreparer() == null )
+ {
+ setServicePreparer( globalServicePreparer );
+ }
+
+ synchronized( descCreatedLock )
+ {
+ descCreated = true;
+ }
+
+ // Get prepared activation system reference
+ Created created = null;
+ ActivationSystem sys =
+ ServiceStarter.getActivationSystem(
+ getActivationSystemHost(),
+ getActivationSystemPort(),
+ config );
+ ProxyPreparer activationIDPreparer =
+ (ProxyPreparer) Config.getNonNullEntry( config,
+ ServiceStarter.START_PACKAGE, "activationIdPreparer",
+ ProxyPreparer.class, new BasicProxyPreparer() );
+
+ if( innerProxyPreparer == null )
+ {
+ innerProxyPreparer = globalServicePreparer;
+ }
+
+ /* Warn user of inaccessible codebase(s) */
+ HTTPDStatus.httpdWarning( getExportCodebase() );
+
+ ActivationGroupID gid = null;
+ ActivationID aid = null;
+ Object proxy = null;
+ try
+ {
+ /* Create the ActivateWrapper descriptor for the desired service */
+ MarshalledObject params =
+ new MarshalledObject( getServerConfigArgs() );
+ ActivateWrapper.ActivateDesc adesc =
+ new ActivateWrapper.ActivateDesc(
+ getImplClassName(),
+ ClassLoaderUtil.getImportCodebaseURLs( getImportCodebase() ),
+ ClassLoaderUtil.getCodebaseURLs( getExportCodebase() ),
+ getPolicy(),
+ params );
+ logger.finest( "ActivateDesc: " + adesc );
+ // Get hosting activation group
+ gid = SharedActivationGroupDescriptor.restoreGroupID(
+ getSharedGroupLog() );
+
+ /* Register the desired service with the activation system */
+ aid = ActivateWrapper.register(
+ gid, adesc, getRestart(), sys );
+ aid = (ActivationID) activationIDPreparer.prepareProxy( aid );
+
+ proxy = aid.activate( true );
+
+ if( proxy != null )
+ {
+ proxy = innerProxyPreparer.prepareProxy( proxy );
+ if( proxy instanceof ServiceProxyAccessor )
+ {
+ proxy = ( (ServiceProxyAccessor) proxy ).getServiceProxy();
+ if( proxy != null )
+ {
+ proxy = getServicePreparer().prepareProxy( proxy );
+ }
+ else
+ {
+ logger.log( Level.FINE,
+ "Service's getServiceProxy() returned null" );
+ }
+ }
+ }//endif
+ }
+ catch( Exception e )
+ {
+ try
+ {
+ if( aid != null )
+ {
+ sys.unregisterObject( aid );
+ }
+ }
+ catch( Exception ee )
+ {
+ // ignore -- did the best we could.
+ logger.log( Level.FINEST,
+ "Unable to unregister with activation system", ee );
+ }
+ if( e instanceof IOException )
+ {
+ throw (IOException) e;
+ }
+ else if( e instanceof ActivationException )
+ {
+ throw (ActivationException) e;
+ }
+ else if( e instanceof ClassNotFoundException )
+ {
+ throw (ClassNotFoundException) e;
+ }
+ else
+ {
+ throw new RuntimeException( "Unexpected Exception", e );
+ }
+ }
+ created = new Created( gid, aid, proxy );
+ logger.exiting( SharedActivatableServiceDescriptor.class.getName(),
+ "create", created );
+ return created;
+ }
+
+ public String toString()
+ {
+ // Would like to call super(), but need different formatting
+ ArrayList fields = new ArrayList( 12 );
+ fields.add( getExportCodebase() );
+ fields.add( getPolicy() );
+ fields.add( getImportCodebase() );
+ fields.add( getImplClassName() );
+ fields.add(
+ ( ( getServerConfigArgs() == null )
+ ? null : Arrays.asList( getServerConfigArgs() ) ) );
+ fields.add( getLifeCycle() );
+ fields.add( getServicePreparer() );
+ fields.add( getInnerProxyPreparer() );
+ fields.add( sharedGroupLog );
+ fields.add( Boolean.valueOf( restart ) );
+ fields.add( host );
+ fields.add( new Integer( port ) );
+ return fields.toString();
+ }
+
+ /**
+ * Reads the default serializable field values for this object.
+ * Also, verifies that the deserialized values are legal.
+ */
+ private void readObject( ObjectInputStream in )
+ throws IOException, ClassNotFoundException
+ {
+ in.defaultReadObject();
+ // Verify serialized fields
+ if( sharedGroupLog == null )
+ {
+ throw new InvalidObjectException( "null shared group log" );
+ }
+ if( host == null )
+ {
+ throw new InvalidObjectException( "null activation host name" );
+ }
+ if( port <= 0 )
+ {
+ throw new InvalidObjectException( "invalid activation port value: " + port );
+ }
+
+ //Reinitialize transient fields upon de-serialization.
+ innerProxyPreparer = null;
+ }
+
+ /**
+ * Throws InvalidObjectException, since data for this class is required.
+ */
+ private void readObjectNoData() throws ObjectStreamException
+ {
+ throw new InvalidObjectException( "no data" );
+ }
+}
+
+
Added: incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedActivationGroupDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedActivationGroupDescriptor.java?rev=724983&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedActivationGroupDescriptor.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedActivationGroupDescriptor.java Tue Dec 9 21:15:48 2008
@@ -0,0 +1,571 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.sun.jini.start;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.rmi.MarshalledObject;
+import java.rmi.activation.ActivationException;
+import java.rmi.activation.ActivationGroupDesc;
+import java.rmi.activation.ActivationGroupDesc.CommandEnvironment;
+import java.rmi.activation.ActivationGroupID;
+import java.rmi.activation.ActivationSystem;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Properties;
+import java.util.logging.Logger;
+import net.jini.config.Configuration;
+
+/**
+ * Class used to create a shared activation group.
+ * Clients construct this object with the details
+ * of the activation group to be launched, then call <code>create</code>
+ * to register the activation system group with the activation system
+ * <P>
+ * This class, in conjunction with the {@link ActivateWrapper} class,
+ * creates an activation group suitable for hosting
+ * multiple service objects, with each object
+ * maintaining a distinct codebase and policy.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+
+public class SharedActivationGroupDescriptor
+ implements ServiceDescriptor, Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ // Required Args
+ /**
+ * @serial <code>String</code> representing VM policy filename or URL
+ */
+ private final String policy;
+
+ /**
+ * @serial <code>String</code> representing the class path of the shared VM
+ * classes
+ */
+ private final String classpath;
+
+ /**
+ * @serial <code>String</code> representing the location where group identifier
+ * information will be persisted
+ */
+ private final String log;
+
+ // Optional Args
+ /**
+ * @serial <code>String</code> representing the VM command to use
+ */
+ private final String serverCommand;
+
+ /**
+ * @serial <code>String[]</code> representing array of command line
+ * options to pass to the VM's command line
+ */
+ private final String[] serverOptions;
+
+ /**
+ * @serial <code>Properties</code> representing propperties to pass
+ * to the VM's command line
+ */
+ private final Properties serverProperties;
+
+ /**
+ * @serial <code>String</code> representing host name of the desired
+ * activation system
+ */
+ private final String host;
+
+ /**
+ * @serial <code>int</code> representing port of the desired activation
+ * system
+ */
+ private final int port;
+
+ private static final String GROUP_COOKIE_FILE = "cookie";
+
+ private static final Logger logger = ServiceStarter.logger;
+
+
+ /**
+ * Trivial constructor. Simply calls the other overloaded constructor
+ * with the <code>host</code> and <code>port</code> parameters set to
+ * <code>null</code> and 0, respectively.
+ */
+ public SharedActivationGroupDescriptor(
+ //Required Args
+ String policy, String classpath, String log,
+ //Optional Args
+ String serverCommand, String[] serverOptions,
+ String[] serverProperties )
+ {
+ this( policy, classpath, log, serverCommand, serverOptions,
+ serverProperties, null,
+ ServiceStarter.getActivationSystemPort() );
+ }
+
+ /**
+ * Trivial constructor. Simply assigns given parameters to
+ * their associated, internal fields.
+ *
+ * @param policy location of VM policy filename or URL
+ * @param classpath location where shared VM
+ * classes can be found. Classpath components must be separated
+ * by path separators.
+ * @param log location where group identifier information will be persisted
+ * @param serverCommand VM command to use
+ * @param serverOptions array of command line options to pass on the VM's
+ * command line
+ * @param serverProperties array of property/value string pairs to
+ * pass on the VMs command line (as in -D<property>=value). This
+ * array must have an even number of elements.
+ * @param host hostname of desired activation system. If <code>null</code>,
+ * defaults to the localhost.
+ * @param port port of desired activation system. If value is <= 0, then
+ * defaults to
+ * {@link java.rmi.activation.ActivationSystem#SYSTEM_PORT
+ * ActivationSystem.SYSTEM_PORT}.
+ */
+ public SharedActivationGroupDescriptor(
+ //Required Args
+ String policy, String classpath, String log,
+ //Optional Args
+ String serverCommand, String[] serverOptions,
+ String[] serverProperties, String host, int port )
+ {
+ if( policy == null || classpath == null || log == null )
+ {
+ throw new NullPointerException(
+ "Policy, classpath, or log cannot be null" );
+ }
+ this.policy = policy;
+ this.classpath = classpath;
+ this.log = log;
+ this.serverCommand = serverCommand;
+ this.serverOptions =
+ customizeSharedGroupOptions( classpath, serverOptions );
+ Properties props =
+ convertToProperties( serverProperties );
+ this.serverProperties =
+ customizeSharedGroupProperties( policy, props );
+ this.host = ( host == null ) ? "" : host;
+ if( port <= 0 )
+ {
+ this.port = ServiceStarter.getActivationSystemPort();
+ }
+ else
+ {
+ this.port = port;
+ }
+ }
+
+ /**
+ * Policy accessor method.
+ *
+ * @return the policy location associated with this service descriptor.
+ */
+ final public String getPolicy()
+ {
+ return policy;
+ }
+
+ /**
+ * Classpath accessor method.
+ *
+ * @return classpath associated with this service descriptor.
+ */
+ final public String getClasspath()
+ {
+ return classpath;
+ }
+
+ /**
+ * Shared group log accessor method.
+ *
+ * @return the shared group log associated with this service descriptor.
+ */
+ final public String getLog()
+ {
+ return log;
+ }
+
+ /**
+ * Command accessor method.
+ *
+ * @return the path-qualified java command name associated with this
+ * service descriptor.
+ */
+ final public String getServerCommand()
+ {
+ return serverCommand;
+ }
+
+ /**
+ * Command options accessor method.
+ *
+ * @return the command options associated with this service descriptor.
+ */
+ final public String[] getServerOptions()
+ {
+ return (String[]) serverOptions.clone();
+ }
+
+ /**
+ * Properties accessor method.
+ *
+ * @return the VM properties associated with this service descriptor.
+ */
+ final public Properties getServerProperties()
+ {
+ return (Properties) serverProperties.clone();
+ }
+
+ /**
+ * Activation system host accessor method.
+ *
+ * @return the activation system host associated with this service descriptor.
+ */
+ final public String getActivationSystemHost()
+ {
+ return host;
+ }
+
+ /**
+ * Activation system port accessor method.
+ *
+ * @return the activation system port associated with this service descriptor.
+ */
+ final public int getActivationSystemPort()
+ {
+ return port;
+ }
+
+ private static String[] customizeSharedGroupOptions(
+ String classpath, String[] userOptions )
+ {
+ String[] customOpts = new String[]{ "-cp", classpath };
+ //Prepend classpath so user options can override later on
+ if( userOptions != null )
+ {
+ String[] tmp = new String[customOpts.length + userOptions.length];
+ System.arraycopy( customOpts, 0, tmp, 0, customOpts.length );
+ System.arraycopy( userOptions, 0, tmp, customOpts.length,
+ userOptions.length );
+ customOpts = tmp;
+ }
+ return customOpts;
+ }
+
+ private static Properties convertToProperties( String[] propertyValues )
+ {
+ Properties properties = new Properties();
+
+ if( propertyValues == null || propertyValues.length == 0 )
+ {
+ return properties;
+ }
+
+ if( propertyValues.length % 2 != 0 )
+ {
+ throw new IllegalArgumentException(
+ "The service properties entry has an odd number of elements" );
+ }
+ for( int i = 0; i < propertyValues.length; i += 2 )
+ {
+ properties.setProperty( propertyValues[ i ], propertyValues[ i + 1 ] );
+ }
+ return properties;
+ }
+
+
+ private static Properties customizeSharedGroupProperties(
+ String policy, Properties userProperties )
+ {
+ // Avoid passing null properties
+ if( userProperties == null )
+ {
+ userProperties = new Properties();
+ }
+ userProperties.put( "java.security.policy", policy );
+
+ return userProperties;
+ }
+
+ /**
+ * Method that attempts to create a shared activation system group from the
+ * description information provided via constructor parameters.
+ * <P>
+ * This method:
+ * <UL>
+ * <LI> creates a
+ * {@link java.rmi.activation.ActivationGroupDesc} with
+ * the provided constructor parameter information
+ * <LI> calls
+ * {@link java.rmi.activation.ActivationSystem#registerGroup(java.rmi.activation.ActivationGroupDesc)
+ * ActivationSystem.registerGroup()} with the constructed
+ * <code>ActivationGroupDesc</code>
+ * <LI> persists the returned
+ * {@link java.rmi.activation.ActivationGroupID activation group identifier}
+ * to the shared group log.
+ * <LI> calls
+ * {@link java.rmi.activation.ActivationSystem#unregisterGroup(java.rmi.activation.ActivationGroupID)
+ * ActivationSystem.unregisterGroup()}
+ * if an exception occurs while persisting the
+ * <code>ActivationGroupID</code>.
+ * </UL>
+ * <EM>Notes:</EM>
+ * <OL>
+ * <LI>Prepends invoking VM's classpath to the server command options.
+ * This allows
+ * subsequent classpath settings to override.
+ * <LI>Adds a <code>"java.security.policy"</code> property with the provided
+ * policy setting to server properties.
+ * </OL>
+ *
+ * @return the
+ * {@link java.rmi.activation.ActivationGroupID} for the newly
+ * created activation system group instance.
+ */
+ public Object create( Configuration config ) throws Exception
+ {
+ ServiceStarter.ensureSecurityManager();
+ logger.entering( SharedActivationGroupDescriptor.class.getName(),
+ "create", new Object[]{ config } );
+
+ if( config == null )
+ {
+ throw new NullPointerException(
+ "Configuration argument cannot be null" );
+ }
+
+//TODO - expand and/or canonicalize classpath components
+
+//TODO - check for shared log existence prior to group creation
+
+ ActivationSystem sys =
+ ServiceStarter.getActivationSystem(
+ getActivationSystemHost(),
+ getActivationSystemPort(),
+ config );
+
+ CommandEnvironment cmdToExecute
+ = new CommandEnvironment( getServerCommand(),
+ getServerOptions() );
+ ActivationGroupID gid = null;
+ try
+ {
+ gid = sys.registerGroup(
+ new ActivationGroupDesc( getServerProperties(),
+ cmdToExecute ) );
+ storeGroupID( getLog(), gid );
+ }
+ catch( Exception e )
+ {
+ try
+ {
+ if( gid != null )
+ {
+ sys.unregisterGroup( gid );
+ }
+ }
+ catch( Exception ee )
+ {
+ // ignore - did the best we could
+ }
+ if( e instanceof IOException )
+ {
+ throw (IOException) e;
+ }
+ else if( e instanceof ActivationException )
+ {
+ throw (ActivationException) e;
+ }
+ else if( e instanceof ClassNotFoundException )
+ {
+ throw (ClassNotFoundException) e;
+ }
+ else
+ {
+ throw new RuntimeException( "Unexpected Exception", e );
+ }
+ }
+
+ logger.exiting( SharedActivationGroupDescriptor.class.getName(),
+ "create", gid );
+ return gid;
+ }
+
+ /**
+ * Stores the <code>created</code> object to a well known file
+ * under the provided <code>dir</code> path.
+ */
+ private static void storeGroupID( final String dir,
+ final ActivationGroupID obj )
+ throws IOException
+ {
+//TODO - create log dir as a separate step
+ File log = new File( dir );
+ String absDir = log.getAbsolutePath();
+ if( log.exists() )
+ {
+ throw new IOException( "Log " + absDir + " exists."
+ + " Please delete or select another path" );
+ }
+ if( !log.mkdir() )
+ {
+ throw new IOException( "Could not create directory: " + absDir );
+// TODO - implement a lock out strategy
+ }
+
+ File cookieFile = new File( log, GROUP_COOKIE_FILE );
+ ObjectOutputStream oos = null;
+ try
+ {
+ oos = new ObjectOutputStream(
+ new BufferedOutputStream(
+ new FileOutputStream( cookieFile ) ) );
+ oos.writeObject( new MarshalledObject( obj ) );
+ oos.flush();
+//TODO - file sync?
+ }
+ catch( IOException e )
+ {
+ cookieFile.delete();
+ throw (IOException) e.fillInStackTrace();
+ }
+ finally
+ {
+ if( oos != null )
+ {
+ oos.close();
+ }
+ }
+ }
+
+ /**
+ * Utility method that restores the object stored in a well known file
+ * under the provided <code>dir</code> path.
+ */
+ static ActivationGroupID restoreGroupID( final String dir )
+ throws IOException, ClassNotFoundException
+ {
+ File log = new File( dir );
+ String absDir = log.getAbsolutePath();
+ if( !log.exists() || !log.isDirectory() )
+ {
+ throw new IOException( "Log directory ["
+ + absDir + "] does not exist." );
+ }
+
+ File cookieFile = new File( log, GROUP_COOKIE_FILE );
+ ObjectInputStream ois = null;
+ ActivationGroupID obj = null;
+ try
+ {
+//TODO - lock out strategy for concurrent r/w file access
+ ois = new ObjectInputStream(
+ new BufferedInputStream(
+ new FileInputStream( cookieFile ) ) );
+ MarshalledObject mo = (MarshalledObject) ois.readObject();
+ obj = (ActivationGroupID) mo.get();
+ }
+ finally
+ {
+ if( ois != null )
+ {
+ ois.close();
+ }
+ }
+ return obj;
+ }
+
+ public String toString()
+ {
+ ArrayList fields = new ArrayList( 8 );
+ fields.add( policy );
+ fields.add( classpath );
+ fields.add( log );
+ fields.add( serverCommand );
+ fields.add( Arrays.asList( serverOptions ) );
+ fields.add( serverProperties );
+ fields.add( host );
+ fields.add( new Integer( port ) );
+ return fields.toString();
+ }
+
+ /**
+ * Reads the default serializable field values for this object.
+ * Also, verifies that the deserialized values are legal.
+ */
+ private void readObject( ObjectInputStream in )
+ throws IOException, ClassNotFoundException
+ {
+ in.defaultReadObject();
+ // Verify that serialized fields
+ if( policy == null )
+ {
+ throw new InvalidObjectException( "null policy" );
+ }
+ if( classpath == null )
+ {
+ throw new InvalidObjectException( "null class path" );
+ }
+ if( log == null )
+ {
+ throw new InvalidObjectException( "null log" );
+ }
+ if( serverOptions == null )
+ {
+ throw new InvalidObjectException( "null server options" );
+ }
+ if( serverProperties == null )
+ {
+ throw new InvalidObjectException( "null server properties" );
+ }
+ if( host == null )
+ {
+ throw new InvalidObjectException( "null activation host name" );
+ }
+ if( port <= 0 )
+ {
+ throw new InvalidObjectException( "invalid activation port: " + port );
+ }
+ }
+
+ /**
+ * Throws InvalidObjectException, since data for this class is required.
+ */
+ private void readObjectNoData() throws ObjectStreamException
+ {
+ throw new InvalidObjectException( "no data" );
+ }
+
+}
+
+
Added: incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedActivationPolicyPermission.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedActivationPolicyPermission.java?rev=724983&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedActivationPolicyPermission.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedActivationPolicyPermission.java Tue Dec 9 21:15:48 2008
@@ -0,0 +1,264 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.sun.jini.start;
+
+import java.io.File;
+import java.io.FilePermission;
+import java.io.Serializable;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+
+/**
+ * {@link Permission} class used by the
+ * {@linkplain com.sun.jini.start service starter}
+ * package. This class takes a policy string argument that follows the
+ * matching semantics defined by {@link FilePermission}. The
+ * {@link ActivateWrapper} class explicitly checks to see if the service's
+ * import codebase has been granted access to service's associated policy
+ * file in the shared VM's policy.
+ * <P>
+ * An example grant is:
+ * <blockquote><pre>
+ * grant codebase "file:<VAR><B>install_dir</B></VAR>/lib/fiddler.jar" {
+ * permission com.sun.jini.start.SharedActivationPolicyPermission
+ * "<VAR><B>policy_dir</B></VAR>${/}policy.fiddler";
+ * };
+ * </pre></blockquote>
+ * This grant allows services using
+ * <code><VAR><B>install_dir</B></VAR>/lib/fiddler.jar</code> for their
+ * import codebase to use
+ * <code><VAR><B>policy_dir</B></VAR>${/}policy.fiddler</code> for their
+ * policy file, where <VAR><B>install_dir</B></VAR> is the installation
+ * directory of the Apache River release and <VAR><B>policy_dir</B></VAR> is the
+ * pathname to the directory containing the policy file.
+ *
+ * @author Sun Microsystems, Inc.
+ */
+public final class SharedActivationPolicyPermission extends Permission
+ implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ /*
+ * Debug flag.
+ */
+ private static final boolean DEBUG = false;
+
+ /**
+ * <code>FilePermission</code> object that is the delegation
+ * target of the <code>implies()</code> checks.
+ *
+ * @serial
+ */
+ private /*final*/ FilePermission policyPermission;
+
+ /**
+ * Constructor that creates a
+ * <code>SharedActivationPolicyPermission</code> with the specified name.
+ * Delegates <code>policy</code> to supertype.
+ */
+ public SharedActivationPolicyPermission( String policy )
+ {
+ //TBD - check for null args
+ super( policy );
+ init( policy );
+ }
+
+ /**
+ * Constructor that creates a
+ * <code>SharedActivationPolicyPermission</code> with the specified name.
+ * This constructor exists for use by the <code>Policy</code> object
+ * to instantiate new Permission objects. The <code>action</code>
+ * argument is currently ignored.
+ */
+ public SharedActivationPolicyPermission( String policy, String action )
+ {
+ //TBD - check for null args
+ super( policy );
+ init( policy );
+ }
+
+ /**
+ * Contains common code to all constructors.
+ */
+ private void init( final String policy )
+ {
+ /*
+ * In order to leverage the <code>FilePermission</code> logic
+ * we need to make sure that forward slashes ("/"), in
+ * <code>URLs</code>, are converted to
+ * the appropriate system dependent <code>File.separatorChar</code>.
+ * For example,
+ * http://host:port/* matches http://host:port/bogus.jar under
+ * UNIX, but not under Windows since "\*" is the wildcard there.
+ */
+ String uncanonicalPath = null;
+ try
+ {
+ URL url = new URL( policy );
+ uncanonicalPath = url.toExternalForm();
+ uncanonicalPath = uncanonicalPath.replace( '/', File.separatorChar );
+ if( DEBUG )
+ {
+ System.out.println( "SharedActivationPolicyPermission::init() - "
+ + policy + " => " + uncanonicalPath );
+ }
+ }
+ catch( MalformedURLException me )
+ {
+ uncanonicalPath = policy;
+ }
+
+ policyPermission = new FilePermission( uncanonicalPath, "read" );
+ }
+
+ // javadoc inherited from superclass
+ public boolean implies( Permission p )
+ {
+
+ // Quick reject tests
+ if( p == null )
+ {
+ return false;
+ }
+ if( !( p instanceof SharedActivationPolicyPermission ) )
+ {
+ return false;
+ }
+
+ SharedActivationPolicyPermission other =
+ (SharedActivationPolicyPermission) p;
+
+ // Delegate to FilePermission logic
+ boolean answer = policyPermission.implies( other.policyPermission );
+
+ if( DEBUG )
+ {
+ System.out.println( "SharedActivationPolicyPermission::implies() - "
+ + "checking " + policyPermission + " vs. "
+ + other.policyPermission + ": " + answer );
+ }
+
+ return answer;
+ }
+
+ /**
+ * Two instances are equal if they have the same name.
+ */
+ public boolean equals( Object obj )
+ {
+ // Quick reject tests
+ if( obj == null )
+ {
+ return false;
+ }
+ if( this == obj )
+ {
+ return true;
+ }
+ if( !( obj instanceof SharedActivationPolicyPermission ) )
+ {
+ return false;
+ }
+
+ SharedActivationPolicyPermission other =
+ (SharedActivationPolicyPermission) obj;
+
+ boolean answer = policyPermission.equals( other.policyPermission );
+ if( DEBUG )
+ {
+ System.out.println( "SharedActivationPolicyPermission::equals() - "
+ + "checking " + policyPermission + " vs. "
+ + other.policyPermission + ": " + answer );
+ }
+
+ return answer;
+ }
+
+ // javadoc inherited from superclass
+ public int hashCode()
+ {
+ return getName().hashCode();
+ }
+
+ // javadoc inherited from superclass
+ public String getActions()
+ {
+ return "";
+ }
+
+ // javadoc inherited from superclass
+ public PermissionCollection newPermissionCollection()
+ {
+ /* bug 4158302 fix */
+ return new Collection();
+ }
+
+ /**
+ * Simple permission collection. See Bug 4158302
+ */
+ private static class Collection extends PermissionCollection
+ {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Permissions
+ *
+ * @serial
+ */
+ private final ArrayList perms = new ArrayList( 3 );
+
+ // javadoc inherited from superclass
+ public synchronized void add( Permission p )
+ {
+ if( isReadOnly() )
+ {
+ throw new SecurityException( "Collection cannot be modified." );
+ }
+
+ if( perms.indexOf( p ) < 0 )
+ {
+ perms.add( p );
+ }
+ }
+
+ // javadoc inherited from superclass
+ public synchronized boolean implies( Permission p )
+ {
+ for( int i = perms.size(); --i >= 0; )
+ {
+ if( ( (Permission) perms.get( i ) ).implies( p ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // javadoc inherited from superclass
+ public Enumeration elements()
+ {
+ return Collections.enumeration( perms );
+ }
+ }
+}
Added: incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedGroup.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedGroup.java?rev=724983&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedGroup.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedGroup.java Tue Dec 9 21:15:48 2008
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.sun.jini.start;
+
+import java.rmi.RemoteException;
+import java.rmi.activation.ActivationException;
+
+/**
+ * The {@linkplain com.sun.jini.start service starter}
+ * supported interface for shared group objects.
+ * Shared group objects are used to destroy the VM in which they are
+ * placed.
+ *
+ * @author Sun Microsystems, Inc.
+ */
+
+public interface SharedGroup
+{
+ /**
+ * Cause the hosting VM to exit.
+ * This method should (in effect) spawn a
+ * separate thread to do the actual work asynchronously,
+ * and make a reasonable attempt to let this remote call
+ * return successfully. As such, a successful return from this
+ * method does not mean that the VM has been
+ * destroyed. Although the service should make a reasonable
+ * attempt to let this remote call return successfully,
+ * the service must not wait indefinitely for other
+ * (in-progress and subsequent) remote calls to finish before
+ * proceeding to destroy its hosting VM. Once this method has been called,
+ * the service can, but need not, reject all other
+ * (in-progress and subsequent) remote calls to the service.
+ *
+ * @throws RemoteException if there was a problem communicating with
+ * the shared group object
+ * @throws ActivationException if there was a problem creating an
+ * activatable shared group instance
+ */
+ public void destroyVM() throws RemoteException, ActivationException;
+}
Added: incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedGroupBackEnd.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedGroupBackEnd.java?rev=724983&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedGroupBackEnd.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedGroupBackEnd.java Tue Dec 9 21:15:48 2008
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.sun.jini.start;
+
+import java.rmi.Remote;
+
+
+/**
+ * The <code>SharedGroupBackEnd</code> interface
+ *
+ * @author Sun Microsystems, Inc.
+ * @see net.jini.admin.Administrable
+ * @see com.sun.jini.start.SharedGroupAdmin
+ * @since 1.2
+ */
+
+interface SharedGroupBackEnd extends SharedGroup, Remote
+{
+ // No additional methods
+}
Added: incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedGroupImpl.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedGroupImpl.java?rev=724983&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedGroupImpl.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/start/src/main/java/com/sun/jini/start/SharedGroupImpl.java Tue Dec 9 21:15:48 2008
@@ -0,0 +1,473 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.sun.jini.start;
+
+import java.rmi.MarshalledObject;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.activation.ActivationException;
+import java.rmi.activation.ActivationGroup;
+import java.rmi.activation.ActivationID;
+import java.rmi.activation.ActivationSystem;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.security.auth.Subject;
+import javax.security.auth.login.LoginContext;
+import net.jini.activation.ActivationExporter;
+import net.jini.config.Configuration;
+import net.jini.config.ConfigurationException;
+import net.jini.config.ConfigurationProvider;
+import net.jini.core.constraint.RemoteMethodControl;
+import net.jini.export.Exporter;
+import net.jini.export.ProxyAccessor;
+import net.jini.export.proxytrust.ServerProxyTrust;
+import net.jini.jeri.BasicILFactory;
+import net.jini.jeri.BasicJeriExporter;
+import net.jini.jeri.tcp.TcpServerEndpoint;
+import net.jini.security.BasicProxyPreparer;
+import net.jini.security.ProxyPreparer;
+import net.jini.security.TrustVerifier;
+
+/**
+ * The provided implementation
+ * of the {@link SharedGroup} service.
+ *
+ * The following items are discussed below:
+ * <ul>
+ * <li><a href="#configEntries">Configuring SharedGroupImpl</a>
+ * <li><a href="#logging">Logging</a>
+ * </ul>
+ *
+ * <a name="configEntries">
+ * <h3>Configuring SharedGroupImpl</h3>
+ * </a>
+ *
+ * This implementation of <code>SharedGroupImpl</code> supports the
+ * following configuration entries, with component
+ * <code>com.sun.jini.start</code>:
+ *
+ * <table summary="Describes the activationIdPreparer configuration entry"
+ * border="0" cellpadding="2">
+ * <tr valign="top">
+ * <th scope="col" summary="layout"> <font size="+1">•</font>
+ * <th scope="col" align="left" colspan="2"> <font size="+1"><code>
+ * activationIdPreparer</code></font>
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Type: <td> {@link net.jini.security.ProxyPreparer}
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Default: <td> <code>
+ * new {@link net.jini.security.BasicProxyPreparer}()
+ * </code>
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Description: <td> The proxy preparer for the service's activation
+ * ID. The value should not be <code>null</code>.
+ *
+ * The service starter calls the
+ * {@link java.rmi.activation.ActivationID#activate
+ * activate} method to activate the service.
+ * </table>
+ *
+ * <table summary="Describes the activationSystemPreparer configuration
+ * entry"
+ * border="0" cellpadding="2">
+ * <tr valign="top">
+ * <th scope="col" summary="layout"> <font size="+1">•</font>
+ * <th scope="col" align="left" colspan="2"> <font size="+1"><code>
+ * activationSystemPreparer</code></font>
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Type: <td> {@link net.jini.security.ProxyPreparer}
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Default: <td> <code>
+ * new {@link net.jini.security.BasicProxyPreparer}()</code>
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Description: <td> The proxy preparer for the proxy for the
+ * activation system. The value should not be <code>null</code>. This
+ * entry is obtained at service start and restart.
+ *
+ * The service calls the {@link
+ * java.rmi.activation.ActivationSystem#unregisterGroup
+ * unregisterGroup} method on the {@link
+ * java.rmi.activation.ActivationSystem} upon service destruction.
+ * </table>
+ *
+ * <table summary="Describes the exporter configuration entry"
+ * border="0" cellpadding="2">
+ * <tr valign="top">
+ * <th scope="col" summary="layout"> <font size="+1">•</font>
+ * <th scope="col" align="left" colspan="2"> <font size="+1"><code>
+ * exporter</code></font>
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Type: <td> {@link net.jini.export.Exporter}
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Default: <td>
+ * <pre>
+ * new {@link net.jini.activation.ActivationExporter}(
+ * <i>activationID</i>,
+ * new {@link net.jini.jeri.BasicJeriExporter}(
+ * {@link net.jini.jeri.tcp.TcpServerEndpoint#getInstance TcpServerEndpoint.getInstance}(0),
+ * new {@link net.jini.jeri.BasicILFactory}(), false, true))
+ * </pre>
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Description: <td> The object to use for exporting the service. The
+ * value should not be <code>null</code>. The call to
+ * <code>getEntry</code> will supply the activation ID in
+ * the <code>data</code> argument. This entry is obtained at service
+ * start and restart.
+ * </table> <p>
+ *
+ * <table summary="Describes the loginContext configuration entry"
+ * border="0" cellpadding="2">
+ * <tr valign="top">
+ * <th scope="col" summary="layout"> <font size="+1">•</font>
+ * <th scope="col" align="left" colspan="2"> <font size="+1"><code>
+ * loginContext</code></font>
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Type: <td> {@link javax.security.auth.login.LoginContext}
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Default: <td> <code>null</code>
+ * <tr valign="top"> <td>   <th scope="row" align="right">
+ * Description: <td> If not <code>null</code>, specifies the JAAS
+ * login context to use for performing a JAAS login and supplying the
+ * {@link javax.security.auth.Subject} to use when running the
+ * service. If <code>null</code>, no JAAS login is performed. This
+ * entry is obtained at service start and restart.
+ * </table>
+ *
+ *
+ * <a name="logging">
+ * <h3>Loggers and Logging Levels</h3>
+ * </a>
+ *
+ * The SharedGroupImpl service implementation uses the {@link
+ * java.util.logging.Logger}, named <code>com.sun.jini.sharedGroup</code>.
+ * The following table describes the
+ * type of information logged as well as the levels of information logged.
+ * <p>
+ *
+ * <table border="1" cellpadding="5"
+ * summary="Describes logging performed by sharedGroup at different
+ * logging levels">
+ *
+ * <caption halign="center" valign="top"><b><code>
+ * com.sun.jini.start.sharedGroup</code></b></caption>
+ *
+ * <tr> <th scope="col"> Level <th scope="col"> Description
+ *
+ * <tr> <td> {@link java.util.logging.Level#FINE FINE} <td>
+ * for low level
+ * service operation tracing
+ * <tr> <td> {@link java.util.logging.Level#FINER FINER} <td>
+ * for lower level
+ * service operation tracing
+ * <tr> <td> {@link java.util.logging.Level#FINEST FINEST} <td>
+ * for lowest level
+ * service operation tracing
+ *
+ * </table> <p>
+ *
+ * @author Sun Microsystems, Inc.
+ */
+public class SharedGroupImpl
+ implements SharedGroupBackEnd, ServerProxyTrust, ProxyAccessor
+{
+
+ /**
+ * Component name for configuration entries
+ */
+ private static final String START_PACKAGE = "com.sun.jini.start";
+
+ /**
+ * Configure logger
+ */
+ private static final Logger logger =
+ Logger.getLogger( START_PACKAGE + ".sharedGroup" );
+
+ /**
+ * Our prepared activation ID reference
+ */
+ private ActivationID activationID = null;
+
+ /**
+ * The prepared activation system reference
+ */
+ private ActivationSystem activationSystem;
+
+ /**
+ * The inner proxy of this server
+ */
+ private Remote ourStub;
+
+ /**
+ * <code>LoginContext</code> for this service.
+ */
+ private final LoginContext loginContext;
+
+ /**
+ * The exporter for exporting and unexporting
+ */
+ protected Exporter exporter;
+
+ /**
+ * Activation constructor.
+ */
+ private SharedGroupImpl( ActivationID activationID, MarshalledObject data )
+ throws Exception
+ {
+ logger.entering( SharedGroupImpl.class.getName(), "SharedGroupImpl",
+ new Object[]{ activationID, data } );
+ this.activationID = activationID;
+ try
+ {
+ String[] configArgs = (String[]) data.get();
+ final Configuration config =
+ ConfigurationProvider.getInstance( configArgs );
+ loginContext = (LoginContext) config.getEntry(
+ START_PACKAGE, "loginContext", LoginContext.class, null );
+ if( loginContext != null )
+ {
+ doInitWithLogin( config, loginContext );
+ }
+ else
+ {
+ doInit( config );
+ }
+ }
+ catch( Exception e )
+ {
+ cleanup();
+ throw e;
+ }
+ logger.exiting( SharedGroupImpl.class.getName(), "SharedGroupImpl" );
+ }
+
+ private void doInitWithLogin( final Configuration config,
+ LoginContext loginContext ) throws Exception
+ {
+ loginContext.login();
+ try
+ {
+ Subject.doAsPrivileged(
+ loginContext.getSubject(),
+ new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ doInit( config );
+ return null;
+ }
+ },
+ null );
+ }
+ catch( PrivilegedActionException e )
+ {
+ throw e.getException();
+ }
+ }
+
+ private void doInit( Configuration config ) throws Exception
+ {
+ ProxyPreparer activationSystemPreparer =
+ (ProxyPreparer) config.getEntry(
+ START_PACKAGE, "activationSystemPreparer",
+ ProxyPreparer.class, new BasicProxyPreparer() );
+ if( activationSystemPreparer == null )
+ {
+ throw new ConfigurationException( START_PACKAGE
+ + ".activationSystemPreparer entry should not be null" );
+ }
+ logger.log( Level.FINE, START_PACKAGE + ".activationSystemPreparer: {0}",
+ activationSystemPreparer );
+
+ ProxyPreparer activationIdPreparer = (ProxyPreparer)
+ config.getEntry( START_PACKAGE, "activationIdPreparer",
+ ProxyPreparer.class, new BasicProxyPreparer() );
+ if( activationIdPreparer == null )
+ {
+ throw new ConfigurationException( START_PACKAGE
+ + ".activationIdPreparer entry should not be null" );
+ }
+ logger.log( Level.FINE, START_PACKAGE + ".activationIdPreparer: {0}",
+ activationIdPreparer );
+
+ // Prepare activation subsystem
+ /*
+ * ActivationGroup is trusted and returned ActivationSystem
+ * might already have been prepared by the group itself.
+ */
+ activationSystem = (ActivationSystem)
+ activationSystemPreparer.prepareProxy(
+ ActivationGroup.getSystem() );
+ logger.log( Level.FINE, "Prepared ActivationSystem: {0}",
+ activationSystem );
+ activationID = (ActivationID)
+ activationIdPreparer.prepareProxy( activationID );
+ logger.log( Level.FINEST, "Prepared ActivationID: {0}",
+ activationID );
+
+ /**
+ * Would like to get this entry sooner, but need to use
+ * the prepared activationID.
+ */
+ exporter = (Exporter) config.getEntry(
+ START_PACKAGE, "exporter", Exporter.class,
+ new ActivationExporter(
+ activationID,
+ new BasicJeriExporter(
+ TcpServerEndpoint.getInstance( 0 ),
+ new BasicILFactory(), false, true ) ),
+ activationID );
+ if( exporter == null )
+ {
+ throw new ConfigurationException( START_PACKAGE
+ + ".exporter entry should not be null" );
+ }
+ logger.log( Level.FINE, START_PACKAGE + ".exporter: {0}",
+ exporter );
+
+ // Export service
+ ourStub = exporter.export( this );
+ logger.log( Level.FINEST, "Exported service proxy: {0}",
+ ourStub );
+ }
+
+ // javadoc inherited from supertype
+ public void destroyVM() throws RemoteException, ActivationException
+ {
+ logger.entering( SharedGroupImpl.class.getName(), "destroyVM" );
+ /*
+ * Would like to synch access to activationSystem, but need
+ * to avoid holding locks across remote invocations.
+ */
+ if( activationSystem != null )
+ {
+ activationSystem.unregisterGroup(
+ ActivationGroup.currentGroupID() );
+ logger.finest( "ActivationGroup unregistered." );
+ /* Unregistering the group implicitly unregisters
+ * all the objects associated with that group as well.
+ */
+ activationSystem = null;
+ }
+ ( new DestroyThread() ).start();
+ logger.exiting( SharedGroupImpl.class.getName(), "destroyVM" );
+ }
+
+ /**
+ * Private utility method which attempts to roll back from
+ * from a failed initialization attempt.
+ */
+ private void cleanup()
+ {
+ logger.entering( SharedGroupImpl.class.getName(), "cleanup" );
+ /*
+ * Caller decides whether or not to unregister this object.
+ */
+ if( exporter != null )
+ {
+ try
+ {
+ // Unexport object so that no new calls come in
+ exporter.unexport( true );
+ logger.finest( "SharedGroupImpl unexported." );
+ }
+ catch( Exception e )
+ {
+ logger.log( Level.FINEST,
+ "Problem unexporting SharedGroupImpl.", e );
+ }
+ }
+
+ if( loginContext != null )
+ {
+ try
+ {
+ loginContext.logout();
+ logger.finest( "SharedGroupImpl logged-out." );
+ }
+ catch( Exception e )
+ {
+ logger.log( Level.FINEST,
+ "Problem logging out for SharedGroupImpl.", e );
+ }
+ }
+ logger.exiting( SharedGroupImpl.class.getName(), "cleanup" );
+ }
+
+ /**
+ * Termination thread code. We do this in a separate thread to
+ * allow the calling thread to return normally. This is not guaranteed
+ * since it's still possible for the VM to exit before the calling
+ * thread returns.
+ */
+ private class DestroyThread extends Thread
+ {
+
+ /**
+ * Create a non-daemon thread
+ */
+ public DestroyThread()
+ {
+ super( "DestroyThread" );
+ /* override inheritance from RMI daemon thread */
+ setDaemon( false );
+ }
+
+ public void run()
+ {
+ logger.entering( DestroyThread.class.getName(),
+ "run" );
+
+ logger.finest( "Calling System.exit() ..." );
+
+ /*
+ * Forcefully destroy the VM, in case there are any lingering
+ * threads.
+ */
+ System.exit( 0 );
+ }
+ }
+
+ // inherit javadoc
+ public Object getProxy()
+ {
+ logger.entering( SharedGroupImpl.class.getName(),
+ "getProxy" );
+ logger.exiting( SharedGroupImpl.class.getName(),
+ "getProxy", ourStub );
+ return ourStub;
+ }
+
+ //////////////////////////////////////////
+ // ProxyTrust Method
+ //////////////////////////////////////////
+ //inherit javadoc
+ public TrustVerifier getProxyVerifier()
+ {
+ /* No verifier if the server isn't secure */
+ if( !( ourStub instanceof RemoteMethodControl ) )
+ {
+ throw new UnsupportedOperationException();
+ }
+ else
+ {
+ return new ProxyVerifier( (SharedGroupBackEnd) ourStub );
+ }
+ }
+}