// // Only for use by IceInternal.ObjectAdapterFactory // public ObjectAdapterI( IceInternal.Instance instance, Communicator communicator, IceInternal.ObjectAdapterFactory objectAdapterFactory, String name, RouterPrx router, boolean noConfig) { _instance = instance; _communicator = communicator; _objectAdapterFactory = objectAdapterFactory; _servantManager = new IceInternal.ServantManager(instance, name); _name = name; _directCount = 0; _noConfig = noConfig; if (_noConfig) { _id = ""; _replicaGroupId = ""; _reference = _instance.referenceFactory().create("dummy -t", ""); _acm = _instance.serverACM(); _messageSizeMax = _instance.messageSizeMax(); return; } final Properties properties = _instance.initializationData().properties; List<String> unknownProps = new ArrayList<String>(); boolean noProps = filterProperties(unknownProps); // // Warn about unknown object adapter properties. // if (unknownProps.size() != 0 && properties.getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0) { StringBuffer message = new StringBuffer("found unknown properties for object adapter `"); message.append(_name); message.append("':"); for (String p : unknownProps) { message.append("\n "); message.append(p); } _instance.initializationData().logger.warning(message.toString()); } // // Make sure named adapter has some configuration. // if (router == null && noProps) { // // These need to be set to prevent finalizer from complaining. // _state = StateDestroyed; _instance = null; _incomingConnectionFactories = null; InitializationException ex = new InitializationException(); ex.reason = "object adapter `" + _name + "' requires configuration"; throw ex; } _id = properties.getProperty(_name + ".AdapterId"); _replicaGroupId = properties.getProperty(_name + ".ReplicaGroupId"); // // Setup a reference to be used to get the default proxy options // when creating new proxies. By default, create twoway proxies. // String proxyOptions = properties.getPropertyWithDefault(_name + ".ProxyOptions", "-t"); try { _reference = _instance.referenceFactory().create("dummy " + proxyOptions, ""); } catch (ProxyParseException e) { InitializationException ex = new InitializationException(); ex.reason = "invalid proxy options `" + proxyOptions + "' for object adapter `" + _name + "'"; throw ex; } _acm = new IceInternal.ACMConfig( properties, communicator.getLogger(), _name + ".ACM", instance.serverACM()); { final int defaultMessageSizeMax = instance.messageSizeMax() / 1024; int num = properties.getPropertyAsIntWithDefault(_name + ".MessageSizeMax", defaultMessageSizeMax); if (num < 1 || num > 0x7fffffff / 1024) { _messageSizeMax = 0x7fffffff; } else { _messageSizeMax = num * 1024; // Property is in kilobytes, _messageSizeMax in bytes } } try { int threadPoolSize = properties.getPropertyAsInt(_name + ".ThreadPool.Size"); int threadPoolSizeMax = properties.getPropertyAsInt(_name + ".ThreadPool.SizeMax"); // // Create the per-adapter thread pool, if necessary. // if (threadPoolSize > 0 || threadPoolSizeMax > 0) { _threadPool = new IceInternal.ThreadPool(_instance, _name + ".ThreadPool", 0); } if (router == null) { router = RouterPrxHelper.uncheckedCast( _instance.proxyFactory().propertyToProxy(name + ".Router")); } if (router != null) { _routerInfo = _instance.routerManager().get(router); if (_routerInfo != null) { // // Make sure this router is not already registered with another adapter. // if (_routerInfo.getAdapter() != null) { throw new AlreadyRegisteredException( "object adapter with router", _instance.identityToString(router.ice_getIdentity())); } // // Add the router's server proxy endpoints to this object // adapter. // IceInternal.EndpointI[] endpoints = _routerInfo.getServerEndpoints(); for (IceInternal.EndpointI endpoint : endpoints) { _routerEndpoints.add(endpoint); } java.util.Collections.sort(_routerEndpoints); // Must be sorted. // // Remove duplicate endpoints, so we have a list of unique // endpoints. // for (int i = 0; i < _routerEndpoints.size() - 1; ) { IceInternal.EndpointI e1 = _routerEndpoints.get(i); IceInternal.EndpointI e2 = _routerEndpoints.get(i + 1); if (e1.equals(e2)) { _routerEndpoints.remove(i); } else { ++i; } } // // Associate this object adapter with the router. This way, // new outgoing connections to the router's client proxy will // use this object adapter for callbacks. // _routerInfo.setAdapter(this); // // Also modify all existing outgoing connections to the // router's client proxy to use this object adapter for // callbacks. // _instance.outgoingConnectionFactory().setRouterInfo(_routerInfo); } } else { // // Parse the endpoints, but don't store them in the adapter. The connection // factory might change it, for example, to fill in the real port number. // List<IceInternal.EndpointI> endpoints = parseEndpoints(properties.getProperty(_name + ".Endpoints"), true); for (IceInternal.EndpointI endp : endpoints) { IncomingConnectionFactory factory = new IncomingConnectionFactory(instance, endp, this, _name); _incomingConnectionFactories.add(factory); } if (endpoints.size() == 0) { IceInternal.TraceLevels tl = _instance.traceLevels(); if (tl.network >= 2) { _instance .initializationData() .logger .trace(tl.networkCat, "created adapter `" + name + "' without endpoints"); } } // // Parse the publsihed endpoints. // _publishedEndpoints = parsePublishedEndpoints(); } if (properties.getProperty(_name + ".Locator").length() > 0) { setLocator( LocatorPrxHelper.uncheckedCast( _instance.proxyFactory().propertyToProxy(_name + ".Locator"))); } else { setLocator(_instance.referenceFactory().getDefaultLocator()); } } catch (LocalException ex) { destroy(); throw ex; } }
@Override public void activate() { IceInternal.LocatorInfo locatorInfo = null; boolean registerProcess = false; boolean printAdapterReady = false; synchronized (this) { checkForDeactivation(); // // If we've previously been initialized we just need to activate the // incoming connection factories and we're done. // if (_state != StateUninitialized) { for (IncomingConnectionFactory factory : _incomingConnectionFactories) { factory.activate(); } return; } // // One off initializations of the adapter: update the // locator registry and print the "adapter ready" // message. We set set state to StateActivating to prevent // deactivation from other threads while these one off // initializations are done. // _state = StateActivating; locatorInfo = _locatorInfo; if (!_noConfig) { final Properties properties = _instance.initializationData().properties; registerProcess = properties.getPropertyAsInt(_name + ".RegisterProcess") > 0; printAdapterReady = properties.getPropertyAsInt("Ice.PrintAdapterReady") > 0; } } try { Ice.Identity dummy = new Ice.Identity(); dummy.name = "dummy"; updateLocatorRegistry(locatorInfo, createDirectProxy(dummy), registerProcess); } catch (Ice.LocalException ex) { // // If we couldn't update the locator registry, we let the // exception go through and don't activate the adapter to // allow to user code to retry activating the adapter // later. // synchronized (this) { _state = StateUninitialized; notifyAll(); } throw ex; } if (printAdapterReady) { System.out.println(_name + " ready"); } synchronized (this) { assert (_state == StateActivating); // // Signal threads waiting for the activation. // _state = StateActive; notifyAll(); for (IncomingConnectionFactory factory : _incomingConnectionFactories) { factory.activate(); } } }