bootstrapserver.java
来自「java jdk 1.4的源码」· Java 代码 · 共 517 行 · 第 1/2 页
JAVA
517 行
String[] services = null; int size = allProps.size() + savedProps.size(); if (size > 0) { services = new String[size]; // Obtain all the keys from the property object Enumeration theKeys = allProps.propertyNames(); for (int index=0;theKeys.hasMoreElements();index++) { services[index] = (String)theKeys.nextElement(); } } return services; } /** * Checks the lastModified() timestamp of the file and optionally * re-reads the Properties object from the file if newer. */protected void check() { // Is there a file to read? if (propFile == null) return; // Assume we already have the object lock long lastMod = propFile.lastModified(); // Up to date? if (lastMod > fileModified) { try { // No, load it again. FileInputStream fileIS = new FileInputStream(propFile); // Clear and reload savedProps.clear(); savedProps.load(fileIS); fileIS.close(); // Set new timestamp fileModified = lastMod; } catch (java.io.FileNotFoundException e) { System.err.println(CorbaResourceUtil.getText("bootstrap.filenotfound", propFile.getAbsolutePath())); } catch (java.io.IOException e) { System.err.println(CorbaResourceUtil.getText("bootstrap.exception",propFile.getAbsolutePath(), e.toString())); } }} private File propFile;private long fileModified;private Properties savedProps;private Properties allProps;}/** * Class BootstrapRequestHandler handles the requests coming to the * BootstrapServer. It implements Server so that it can be registered * as a subcontract. It is passed a BootstrapServiceProperties object * which contains * the supported ids and their values for the bootstrap service. This * Properties object is only read from, never written to, and is shared * among all threads. * <p> * The BootstrapRequestHandler responds primarily to GIOP requests, * but LocateRequests are (reluctantly) handled for graceful interoperability. * The BootstrapRequestHandler handles one request at a time. */final class BootstrapRequestHandler implements ServerSubcontract{ public static final int OBJECT_KEY_BAD_LEN = 10000; public static final int OPERATION_NOT_GET_OR_LIST = 10001; public static final int JAVA_RUNTIME_EXC_CAUGHT = 10002; public static final int JAVA_EXC_CAUGHT = 10003; private com.sun.corba.se.internal.iiop.ORB orb; private BootstrapServiceProperties props; private static final boolean debug = false; public BootstrapRequestHandler(com.sun.corba.se.internal.iiop.ORB orb, BootstrapServiceProperties props) { this.orb = orb; this.props = props; } public void destroyObjref(java.lang.Object objref) { } /** * Dispatch is called by the ORB and will serve get(key) and list() * invocations on the initial object key. */ public com.sun.corba.se.internal.core.ServerResponse dispatch( com.sun.corba.se.internal.core.ServerRequest request) { com.sun.corba.se.internal.core.ServerResponse response = null; try { MarshalInputStream is = (MarshalInputStream) request; String method = request.getOperationName(); response = request.createResponse(null); MarshalOutputStream os = (MarshalOutputStream) response; if (method.equals("get")) { // Get the name of the requested service String service_key = is.read_string(); // Look it up String service_value = props.get(service_key); org.omg.CORBA.Object service_obj = null; if (service_value != null) { try { service_obj = orb.string_to_object(service_value); } catch (org.omg.CORBA.SystemException e) {} } if (debug) System.out.println("BootstrapRequestHandler: get(" + service_key + ") -> " + service_value); // Write reply value os.write_Object(service_obj); } else if (method.equals("list")) { // Get all known keys String keys[] = props.keys(); int keys_len = 0; if (keys == null) keys = new String[0]; else keys_len = keys.length; if (debug) System.out.println("BootstrapRequestHandler: list() -> " + keys_len + " entries."); // Write length of sequence os.write_long(keys_len); // Write each string in the sequence for (int i=0;i<keys_len;i++) { os.write_string(keys[i]); } } else { // Bad operation if (debug) System.out.println(method); throw new BAD_OPERATION(OPERATION_NOT_GET_OR_LIST, CompletionStatus.COMPLETED_NO); } } catch (org.omg.CORBA.SystemException ex) { // Marshal the exception thrown if (debug) ex.printStackTrace(); response = request.createSystemExceptionResponse(ex, null); } catch (java.lang.RuntimeException ex) { // Unknown exception if (debug) ex.printStackTrace(); response = request.createSystemExceptionResponse( new UNKNOWN(ex.toString(), JAVA_RUNTIME_EXC_CAUGHT, CompletionStatus.COMPLETED_NO), null); } catch (java.lang.Exception ex) { // Unknown exception if (debug) ex.printStackTrace(); response = request.createSystemExceptionResponse( new UNKNOWN(ex.toString(), JAVA_EXC_CAUGHT, CompletionStatus.COMPLETED_NO), null); } return response; } /** * Locates the object mentioned in the locate requests, and returns * object here iff the object is the initial object key. A SystemException * thrown if the object key is not the initial object key. */ public com.sun.corba.se.internal.core.IOR locate( com.sun.corba.se.internal.ior.ObjectKey objectKey) { return null; } /** * Not implemented; throws org.omg.CORBA.NO_IMPLEMENT(). */public java.lang.Object createObjref( IOR ior ){ throw new NO_IMPLEMENT();}/** * Not implemented; throws org.omg.CORBA.NO_IMPLEMENT(). */public java.lang.Object createObjref(byte[] key, java.lang.Object servant){ throw new NO_IMPLEMENT();}/** * Not implemented; throws org.omg.CORBA.NO_IMPLEMENT(). */public byte[] getKey(org.omg.CORBA.Object objref){ throw new NO_IMPLEMENT();}/** * Not implemented; throws org.omg.CORBA.NO_IMPLEMENT(). */public int getImplId(org.omg.CORBA.Object objref){ throw new NO_IMPLEMENT();}/** * isServantSupported should return null */public boolean isServantSupported(){ return false;}/** * Not implemented; throws org.omg.CORBA.NO_IMPLEMENT(). */public java.lang.Object getServant(IOR ior) { throw new NO_IMPLEMENT();}/** * Not implemented; throws org.omg.CORBA.NO_IMPLEMENT(). */public void setOrb(com.sun.corba.se.internal.core.ORB orb) { throw new NO_IMPLEMENT();}/** * Not implemented; throws org.omg.CORBA.NO_IMPLEMENT(). */public void setId(int scid) { throw new NO_IMPLEMENT();}/** * Not implemented; throws org.omg.CORBA.NO_IMPLEMENT(). */public int getId() { throw new NO_IMPLEMENT();}/** * Not implemented; throws org.omg.CORBA.NO_IMPLEMENT(). */public java.lang.Class getClientSubcontractClass() { throw new NO_IMPLEMENT();}}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?