mcconnell 02/02/02 02:28:38
Added: apps/enterprise/orb/src/java/org/apache/orb
ORBConfigurationHelper.java ORBServer.java
ORBServer.xinfo ORBService.java package.html
Log:
Inital posting of ORB component and related resources.
Revision Changes Path
1.1
jakarta-avalon-cornerstone/apps/enterprise/orb/src/java/org/apache/orb/ORBConfigurationHelper.java
Index: ORBConfigurationHelper.java
===================================================================
/**
* File: ORBConfigurationHelper.java
* License: etc/LICENSE.TXT
* Copyright: Copyright (C) The Apache Software Foundation. All rights
reserved.
* Copyright: OSM SARL 2001-2002, All Rights Reserved.
*/
package org.apache.orb;
import java.io.File;
import java.net.URL;
import java.util.Properties;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
/**
* Utility class that provides supporting operations related to the ORB
* element encountered in configurationi files. This class can be
* instantiated by passing a Configiration instance to the constructor,
* where the configuration instance is a node named 'ORB'. The class
* provides a set of operations that simplfy the extraction of properties
* and other ORB related information - enabling simplificatiuon of
* configuration code that is depenedent on the establishement of an ORB
* runtime environment.
*
* @author Stephen McConnell
*/
public class ORBConfigurationHelper
{
//====================================================================
// state
//====================================================================
private static final boolean trace = false;
/**
* The default ORB class.
*/
protected static final String DEFAULT_ORB_CLASS =
"org.openorb.CORBA.ORB";
/**
* The default ORB Singleton class.
*/
protected static final String DEFAULT_ORB_SINGLETON =
"org.openorb.CORBA.ORBSingleton";
/**
* The Configuration instance supplied to the constructor.
*/
protected Configuration configuration;
/**
* Root directory from which file and URL relative reference shall be
resolved.
*/
protected File root;
//====================================================================
// Constructors
//====================================================================
public ORBConfigurationHelper( Configuration config )
{
this( config, new File( System.getProperty("user.dir") ) );
}
public ORBConfigurationHelper( Configuration config, File root )
{
final String nullError = "null configuration supplied to constructor";
final String badName = "configuration element is not named 'orb'";
if( config == null ) throw new RuntimeException( nullError );
String name = config.getName();
if( !name.equals("orb") ) throw new RuntimeException( badName );
this.configuration = config;
this.root = root;
}
//====================================================================
// implementation
//====================================================================
/**
* Return a Properties instance based on the ORB class and singleton
delcarations
* together with containing property declarations. The properties
instance is
* provided in a form suitable for passing to an ORB.init() method.
*/
public Properties getProperties( ) throws Exception
{
Properties p = new Properties();
String orbClass =
configuration.getAttribute("org.omg.CORBA.ORBClass", DEFAULT_ORB_CLASS );
String orbSingleton =
configuration.getAttribute("org.omg.CORBA.ORBSingletonClass",
DEFAULT_ORB_SINGLETON );
p.setProperty("org.omg.CORBA.ORBClass", orbClass );
p.setProperty("org.omg.CORBA.ORBSingletonClass", orbSingleton );
//
// resolve any ORB specific properties
//
Configuration[] props = configuration.getChildren("property");
for( int i = 0; i< props.length; i++ )
{
Configuration child = props[i];
//
// every property must have a name
//
String name = "";
try
{
name = child.getAttribute("name");
}
catch( ConfigurationException noName )
{
final String error = "encountered a property without a
name";
throw new Exception ( error, noName );
}
//
// The value of a property is either declared directly under a
value attribute,
// or indirectory under a 'file' attribute. In the case of
'file' attributes
// we need to resolve this relative to this file before setting
the
// property value.
//
String value = "";
try
{
value = child.getAttribute("value");
}
catch( ConfigurationException noValueAttribute )
{
try
{
final String s = child.getAttribute("file");
File f = new File( root, s );
value = f.getAbsolutePath();
}
catch( ConfigurationException noFileAttribute )
{
String s = null;
try
{
s = child.getAttribute("url");
}
catch( Exception noURL )
{
final String error = "Found a property without
a 'value', 'file' or 'url' attribute";
throw new Exception( error, noURL );
}
if( s.startsWith("file:"))
{
try
{
URL base = root.toURL();
URL url = new URL( base, s );
value = url.toString();
if( trace ) System.out.println( "URL: " +
value );
}
catch( Exception unknown )
{
final String error = "Unexpected exception
while creating file:// URL value.";
throw new Exception( error, unknown );
}
}
else
{
try
{
URL url = new URL( s );
if( trace ) System.out.println( "URL: " + url
);
value = url.toString();
if( trace ) System.out.println( "URL/value: "
+ value );
}
catch( Exception unknown )
{
final String error = "Unexpected exception
while creating URL value.";
throw new Exception( error
+ "\n" + "cause: " +
unknown.getClass().getName() + ", "
+ "\n" + unknown.getMessage(), unknown
);
}
}
}
}
p.setProperty( name, value );
}
return p;
}
}
1.1
jakarta-avalon-cornerstone/apps/enterprise/orb/src/java/org/apache/orb/ORBServer.java
Index: ORBServer.java
===================================================================
/**
* File: ORBServer.java
* License: etc/LICENSE.TXT
* Copyright: Copyright (C) The Apache Software Foundation. All rights
reserved.
* Copyright: OSM SARL 2001-2002, All Rights Reserved.
*/
package org.apache.orb;
import java.io.File;
import java.util.Properties;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.activity.Startable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.phoenix.Block;
import org.apache.avalon.phoenix.BlockContext;
import org.omg.CORBA_2_3.ORB;
/**
* The <code>ORBServer</code> class is an Avalon block that encapsulates the
configuration
* initalization and startup of a portable ORB service.
*
* <p><table border="1" cellpadding="3" cellspacing="0" width="100%">
* <tr bgcolor="#ccccff">
* <td colspan="2"><b><code>ORBServer</code>Lifecycle Phases</b></td>
* <tr><td width="20%"></td><td><b>Description</b></td></tr>
* <tr>
* <td width="20%"><b>Contextualizable</b></td>
* <td>
* The <code>Context</code> value passed to the <code>ORBServer</code> during
this phase
* provides the runtime execution context including the root application
directory
* from which a ORB configuration file can be resolved.</td></tr>
* <tr>
* <td width="20%"><b>Configurable</b></td>
* <td>
* The configuration phase handles the internalization of a static
configuration data
* including ORB bootstrap properties and ORB specific execution properties.
* </td></tr>
* <tr><td width="20%"><b>Initalizable</b></td>
* <td>
* The initialization phases handles the initialization of the ORB.
* </td></tr>
* <tr><td width="20%"><b>Startable</b></td>
* <td>
* Handles startup and shutdown of the ORB.
* </td></tr>
* <tr><td width="20%"><b>Disposable</b></td>
* <td>
* Handles the release of resources consumed by the ORB.
* </td></tr>
* </table>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
*/
public class ORBServer extends AbstractLogEnabled
implements Block, Contextualizable, Configurable, Initializable, Startable,
Disposable, ORBService
{
//=================================================================
// state
//=================================================================
/**
* The configuration is an in memory representation of the XML assembly
file used
* as a container of static configuration values.
*/
private Configuration configuration;
/**
* The main server object request broker established by this server and
* made available under <code>getOrb</code> method.
*/
private ORB orb;
/**
* Thread used to run the orb.
*/
private Thread thread;
/**
* Properties to be passed to the ORB initialization function.
*/
private Properties props;
/**
* Base directory for the application.
*/
File baseDirectory;
/**
* Application context
*/
BlockContext context;
//=================================================================
// Contextualizable
//=================================================================
public void contextualize( Context context ) throws ContextException
{
if( getLogger().isDebugEnabled() ) getLogger().debug( "contextualize"
);
if( context instanceof BlockContext )
{
this.context = (BlockContext) context;
}
else
{
final String error = "supplied context does not implement
BlockContext";
throw new ContextException( error );
}
}
//==========================================================================
// Configurable
//==========================================================================
/**
* Configuration of the runtime environment based on a supplied
Configuration arguments
* which contains the general arguments for ORB initalization, PSS
subsystem initialization,
* PSDL type to class mappings, preferences and debug information.
*
* @param config Configuration representing an internalized model of the
assembly.xml file.
* @exception ConfigurationException if the supplied configuration is
incomplete or badly formed.
*/
public void configure( final Configuration config )
throws ConfigurationException
{
if( getLogger().isDebugEnabled() ) getLogger().debug( "configure" );
if( null != configuration ) throw new ConfigurationException(
"Configurations for block " + this + " already set" );
this.configuration = config;
}
//=================================================================
// Initializable
//=================================================================
/**
* Initialization is invoked by the framework following configuration,
during which
* the ORB is initialized.
*/
public void initialize()
throws Exception
{
final String pre = "ORB intialization";
// Collection of the ORB initalization arguments.
//
try
{
File root = context.getBaseDirectory();
ORBConfigurationHelper helper = new ORBConfigurationHelper(
configuration, root );
props = helper.getProperties();
}
catch (Exception e)
{
final String error = "Failed to establish ORB properties in ";
throw new ConfigurationException( error +
context.getBaseDirectory(), e);
}
if( getLogger().isDebugEnabled() ) getLogger().debug( pre );
try
{
orb = (ORB) ORB.init( new String[0], props );
}
catch ( Throwable e )
{
final String error = "ORB initialization failure under ";
throw new Exception( error + context.getBaseDirectory(), e );
}
final String banner = "OSM ORB Service";
if( getLogger().isInfoEnabled() ) getLogger().info( banner );
System.out.println( banner );
}
//=================================================================
// Startable
//=================================================================
/**
* The start operation is invoked by a manager following completion of the
* initialization phase, during which a new thread is created for the
execution
* of the ORB.
*/
public void start()
throws Exception
{
final String status = "start";
thread = new Thread(
new Runnable() {
public void run()
{
if( getLogger().isDebugEnabled() ) getLogger().debug( status
);
try
{
orb.run();
}
catch (Exception e)
{
final String error = "unexpected exception raised by
the ORB";
if( getLogger().isErrorEnabled() ) getLogger().error(
error, e );
throw new RuntimeException( error, e );
}
}
}
);
thread.start();
final String debug = "statup complete";
if( getLogger().isDebugEnabled() ) getLogger().debug( debug );
}
/**
* Stops the component.
*/
public void stop()
throws Exception
{
if( getLogger().isDebugEnabled() ) getLogger().debug( "stop" );
try
{
orb.shutdown( true );
}
catch( Throwable e )
{
final String warning = "Internal error while shutting down the
ORB.";
if( getLogger().isWarnEnabled() ) getLogger().warn( warning, e );
}
}
//=================================================================
// Disposable
//=================================================================
/**
* Notification by the framework requesting disposal of this component.
*/
public synchronized void dispose()
{
if( getLogger().isDebugEnabled() ) getLogger().debug( "disposal" );
try
{
orb.destroy();
}
catch( org.omg.CORBA.NO_IMPLEMENT e )
{
// ignore
}
catch( Throwable e )
{
final String warning = "Internal error while disposing of ORB
related resources.";
if( getLogger().isWarnEnabled() ) getLogger().warn( warning, e
);
}
this.orb = null;
this.thread = null;
this.context = null;
this.configuration = null;
this.props = null;
}
//=================================================================
// ORBService
//=================================================================
/**
* Returns the current ORB for the purpose of valuetype initialization and
other
* ORB related operations.
*/
public ORB getOrb( )
{
return orb;
}
}
1.1
jakarta-avalon-cornerstone/apps/enterprise/orb/src/java/org/apache/orb/ORBServer.xinfo
Index: ORBServer.xinfo
===================================================================
<?xml version="1.0"?>
<!--
File: ORBConfigurationHelper.java
License: etc/LICENSE.TXT
Copyright: Copyright (C) The Apache Software Foundation. All rights reserved.
Copyright: OSM SARL 2001-2002, All Rights Reserved.
@author Stephen McConnell
@version 1.0 12/03/2001
-->
<blockinfo>
<block>
<version>1.0</version>
</block>
<!--
services that are offered by this block
-->
<services>
<service name="org.apache.orb.ORBService" version="2.4" />
</services>
</blockinfo>
1.1
jakarta-avalon-cornerstone/apps/enterprise/orb/src/java/org/apache/orb/ORBService.java
Index: ORBService.java
===================================================================
/**
* File: ORBService.java
* License: etc/LICENSE.TXT
* Copyright: Copyright (C) The Apache Software Foundation. All rights
reserved.
* Copyright: OSM SARL 2001-2002, All Rights Reserved.
*/
package org.apache.orb;
import org.apache.avalon.framework.component.Component;
import org.omg.CORBA_2_3.ORB;
/**
* The ORBService is an interface facilitating access to the runtime ORB. The
* ORB instance exposed by the <code>getOrb</code> operation is an ORB
supporting
* the CORBA 2.3 portability specification.
* @author Stephen McConnell <[EMAIL PROTECTED]>
*/
public interface ORBService extends Component
{
/**
* Returns the current ORB.
* @return ORB a portable CORBA Object Request Broker (ORB)
*/
public ORB getOrb( );
}
1.1
jakarta-avalon-cornerstone/apps/enterprise/orb/src/java/org/apache/orb/package.html
Index: package.html
===================================================================
<body>
<p>AN ORB Block that can be used as a formal Phoenix server block or embedded
component.</p>
</body>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>