📄 corbadriver.java
字号:
/*------------------------------------------------------------------------------Name: CorbaDriver.javaProject: xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE fileComment: CorbaDriver class to invoke the xmlBlaster server using CORBA.Version: $Id: CorbaDriver.java 15510 2006-09-17 18:54:55Z ruff $------------------------------------------------------------------------------*/package org.xmlBlaster.protocol.corba;import java.util.logging.Logger;import java.util.logging.Level;import org.xmlBlaster.util.FileLocator;import org.xmlBlaster.util.Global;import org.xmlBlaster.util.XmlBlasterException;import org.xmlBlaster.util.context.ContextNode;import org.xmlBlaster.util.def.ErrorCode;import org.xmlBlaster.util.def.Constants;import org.xmlBlaster.util.protocol.corba.OrbInstanceFactory;import org.xmlBlaster.protocol.I_Authenticate;import org.xmlBlaster.protocol.I_XmlBlaster;import org.xmlBlaster.protocol.I_Driver;import org.xmlBlaster.protocol.corba.authenticateIdl.AuthServerPOATie;import org.xmlBlaster.protocol.corba.AuthServerImpl;import org.xmlBlaster.engine.qos.AddressServer;import java.io.PrintWriter;import java.io.FileOutputStream;import java.io.File;import org.omg.CosNaming.NamingContext;import org.omg.CosNaming.NamingContextExt;import org.omg.CosNaming.NameComponent;/** * CorbaDriver class to invoke the xmlBlaster server using CORBA. * Note the IANA assigned official CORBA ports: * <pre> * corba-iiop 683/tcp CORBA IIOP * corba-iiop 683/udp CORBA IIOP * corba-iiop-ssl 684/tcp CORBA IIOP SSL * corba-iiop-ssl 684/udp CORBA IIOP SSL * * corbaloc 2809/tcp CORBA LOC * corbaloc 2809/udp CORBA LOC * </pre> * We use the following CORBA specific ports: * <pre> * 7608 as the default port to look for a naming service * 3412 is the xmlBlaster assigned port, used for bootstrapping (optional) * </pre> * JacORB CORBA socket:<br /> * org.jacorb.util.Environment.getProperty("OAIAddr");<br /> * org.jacorb.util.Environment.getProperty("OAPort"); * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/protocol.corba.JacORB.html">The protocol.corba.JacORB requirement</a> * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/protocol.corba.NameService.html">The protocol.corba.NameService requirement</a> */public class CorbaDriver implements I_Driver, CorbaDriverMBean{ private String ME = "CorbaDriver"; private org.omg.CORBA.ORB orb; private Global glob; private static Logger log = Logger.getLogger(CorbaDriver.class.getName()); private NamingContextExt namingContextExt; private NameComponent [] nameXmlBlaster; private NameComponent [] nameNode; private String iorFile; /** The singleton handle for this xmlBlaster server */ private AuthServerImpl authServer; /** The singleton handle for this xmlBlaster server */ private I_Authenticate authenticate; /** The singleton handle for this xmlBlaster server */ private I_XmlBlaster xmlBlasterImpl; private org.omg.PortableServer.POA rootPOA; private org.omg.CORBA.Object authRef; /** The URL path over which the IOR can be accessed (via our http bootstrap server) */ private final String urlPath = "/AuthenticationService.ior"; private AddressServer addressServer; /** My JMX registration, can be done optionally by implementing classes */ protected Object mbeanHandle; protected ContextNode contextNode; protected boolean isActive; /** Get a human readable name of this driver */ public String getName() { return ME; } /** * Access the xmlBlaster internal name of the protocol driver. * @return "IOR" */ public String getProtocolId() { return "IOR"; } /** Enforced by I_Plugin */ public String getType() { return getProtocolId(); } /** Enforced by I_Plugin */ public String getVersion() { return "1.0"; } /** * This method is called by the PluginManager (enforced by I_Plugin). * @see org.xmlBlaster.util.plugin.I_Plugin#init(org.xmlBlaster.util.Global,org.xmlBlaster.util.plugin.PluginInfo) */ public void init(org.xmlBlaster.util.Global glob, org.xmlBlaster.util.plugin.PluginInfo pluginInfo) throws XmlBlasterException { this.glob = glob; this.ME = "CorbaDriver" + this.glob.getLogPrefixDashed(); org.xmlBlaster.engine.ServerScope engineGlob = (org.xmlBlaster.engine.ServerScope)glob.getObjectEntry(Constants.OBJECT_ENTRY_ServerScope); if (engineGlob == null) throw new XmlBlasterException(this.glob, ErrorCode.INTERNAL_UNKNOWN, ME + ".init", "could not retreive the ServerNodeScope. Am I really on the server side ?"); try { this.authenticate = engineGlob.getAuthenticate(); if (this.authenticate == null) { throw new XmlBlasterException(this.glob, ErrorCode.INTERNAL_UNKNOWN, ME + ".init", "authenticate object is null"); } I_XmlBlaster xmlBlasterImpl = this.authenticate.getXmlBlaster(); if (xmlBlasterImpl == null) { throw new XmlBlasterException(this.glob, ErrorCode.INTERNAL_UNKNOWN, ME + ".init", "xmlBlasterImpl object is null"); } // For JMX instanceName may not contain "," this.contextNode = new ContextNode(ContextNode.SERVICE_MARKER_TAG, "CorbaDriver[" + getType() + "]", glob.getContextNode()); this.mbeanHandle = this.glob.registerMBean(this.contextNode, this); init(glob, new AddressServer(glob, getType(), glob.getId(), pluginInfo.getParameters()), this.authenticate, xmlBlasterImpl); activate(); } catch (XmlBlasterException ex) { throw ex; } catch (Throwable ex) { throw new XmlBlasterException(this.glob, ErrorCode.INTERNAL_UNKNOWN, ME + ".init", "init. Could'nt initialize the driver.", ex); } } /** * Get the address how to access this driver. * @return "IOR:00034500350..." */ public String getRawAddress() { if (this.orb == null || this.authRef == null) return null; return this.orb.object_to_string(this.authRef); } /** * Start xmlBlaster CORBA access. * Is called after plugin is created * @param args The command line parameters */ private synchronized void init(Global glob, AddressServer addressServer, I_Authenticate authenticate, I_XmlBlaster xmlBlasterImpl) throws XmlBlasterException { this.authenticate = authenticate; this.xmlBlasterImpl = xmlBlasterImpl; this.addressServer = addressServer; this.orb = OrbInstanceFactory.createOrbInstance(this.glob, (String[])null, glob.getProperty().getProperties(), addressServer); try { rootPOA = org.omg.PortableServer.POAHelper.narrow(orb.resolve_initial_references("RootPOA")); rootPOA.the_POAManager().activate(); authServer = new AuthServerImpl(glob, orb, this.addressServer, this.authenticate, this.xmlBlasterImpl); // USING TIE: org.omg.PortableServer.Servant authServant = new AuthServerPOATie(authServer); this.authRef = ((AuthServerPOATie)(authServant))._this(orb); this.addressServer.setRawAddress(orb.object_to_string(this.authRef)); } catch (org.omg.CORBA.COMM_FAILURE e) { throw new XmlBlasterException(glob, ErrorCode.RESOURCE_CONFIGURATION, ME, "Could not initialize CORBA, do you use the SUN-JDK delivered ORB instead of JacORB or ORBaccus? Try 'jaco org.xmlBlaster.Main' and read instructions in xmlBlaster/bin/jaco", e); } catch (Throwable e) { e.printStackTrace(); throw new XmlBlasterException(glob, ErrorCode.RESOURCE_CONFIGURATION, ME, "Could not initialize CORBA", e); } } /** * Activate xmlBlaster access through this protocol. */ public synchronized void activate() throws XmlBlasterException { if (log.isLoggable(Level.FINER)) log.finer("Entering activate"); try { // NOT TIE: // org.omg.PortableServer.Servant authServant = new AuthServerImpl(orb); // this.authRef = rootPOA.servant_to_reference(authServant); // There are three variants how xmlBlaster publishes its AuthServer IOR (object reference) // 1) Write IOR to given file iorFile = this.addressServer.getEnv("iorFile", "").getValue(); if (log.isLoggable(Level.FINE)) log.fine(this.addressServer.getEnvLookupKey("iorFile") + " = " + iorFile); if(iorFile != null && iorFile.length() > 0) { PrintWriter ps = new PrintWriter(new FileOutputStream(new File(iorFile))); //if (log.isLoggable(Level.FINEST)) log.dump(ME, "Dumping authRef=" + this.authRef + " to " + iorFile + ": " + orb.object_to_string(this.authRef)); ps.println(orb.object_to_string(this.authRef)); ps.close(); log.info("Published AuthServer IOR to file " + iorFile + ", this will be deleted on shutdown."); } // 2) Publish IOR on given port (switch off this feature with '-bootstrapPort 0' if (glob.getBootstrapAddress().getBootstrapPort() > 0) { glob.getHttpServer().registerRequest(urlPath, orb.object_to_string(this.authRef)); log.info("Published AuthServer IOR on " + glob.getBootstrapAddress().getRawAddress()); } // 3) Publish IOR to a naming service -plugin/ior/useNameService true/false boolean useNameService = this.addressServer.getEnv("useNameService", true).getValue(); // default is to publish myself to the naming service if (useNameService) { /* // We check if a name server is running, if not we just create and start one: Class nameServer = Class.forName("jacorb.naming.NameServer"); if (nameServer != null) { try { namingContextExt = getNamingService(); } catch (XmlBlasterException e) { class MyNameServer extends Thread { public void run() { Thread.currentThread().setName("XmlBlaster CorbaDriver NameServerThread"); String[] aa = new String[1]; // !!! where do we get the document root from (see jacorb.NameServerURL in jacorb.properties)? aa[0] = "/home/ruff/xmlBlaster/demo/html/NS_Ref"; // !!! using reflection in future to avoid JacORB dependency (nameServer. Method main): jacorb.naming.NameServer.main(aa); log.info(ME, "Created Name server"); } } MyNameServer thr = new MyNameServer(); thr.start(); Timestamp.sleep(500); log.info(ME, "Started CORBA naming service"); } } */ // Register xmlBlaster with a name server: // NameService entry is e.g. xmlBlaster.MOM/heron.MOM try { namingContextExt = getNamingService(); String contextId = this.addressServer.getEnv("NameService.context.id", "xmlBlaster").getValue(); String contextKind = this.addressServer.getEnv("NameService.context.kind", "MOM").getValue(); nameXmlBlaster = new NameComponent[1]; nameXmlBlaster[0] = new NameComponent(); nameXmlBlaster[0].id = contextId; // old style: "xmlBlaster-Authenticate" nameXmlBlaster[0].kind = contextKind; // kind is like a file extension (does not make much sense here) NamingContext relativeContext = null; int numTries = 5; // We need to retry for(int i=0; i<numTries; i++) { try { relativeContext = namingContextExt.bind_new_context(nameXmlBlaster); if (relativeContext != null) { break; } } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound ex) { if (log.isLoggable(Level.FINE)) log.fine("Can't register CORBA NameService context '" + OrbInstanceFactory.getString(nameXmlBlaster) + "': " + ex.toString()); try { org.omg.CORBA.Object obj = namingContextExt.resolve(nameXmlBlaster); relativeContext = org.omg.CosNaming.NamingContextExtHelper.narrow(obj); break; } catch (Throwable e) { log.severe("Can't register CORBA NameService context '" + OrbInstanceFactory.getString(nameXmlBlaster) + "', #"+i+"/"+numTries+": " + e.toString()); } } catch (org.omg.CORBA.NO_IMPLEMENT ex) { // JacORB 1.3.x bug (remove this catch when updated to JacORB 1.4x) if (log.isLoggable(Level.FINE)) log.fine("Can't register CORBA NameService context '" + OrbInstanceFactory.getString(nameXmlBlaster) + "': " + ex.toString()); try { org.omg.CORBA.Object obj = namingContextExt.resolve(nameXmlBlaster); relativeContext = org.omg.CosNaming.NamingContextExtHelper.narrow(obj);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -