📄 stdpeergroup.java
字号:
if (Logging.SHOW_FINER && LOG.isLoggable(Level.FINER)) { LOG.finer("Service stalled during start : " + aModule); } break; case Module.START_DISABLED: if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("Service declined to start : " + aModule); } eachService.remove(); progress = true; break; default: // (negative) if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) { LOG.warning("Service failed to start (" + res + ") : " + aModule); } eachService.remove(); progress = true; break; } } if (progress) { maxIterations = services.size() * services.size() + iterations + 1; } } // Uh-oh. Services co-dependency prevented them from starting. if (!services.isEmpty()) { if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { StringBuilder failed = new StringBuilder( "No progress is being made in starting services after " + iterations + " iterations. Giving up."); failed.append("\nThe following services could not be started : "); for (Map.Entry<ModuleClassID, Module> aService : services.entrySet()) { failed.append("\n\t"); failed.append(aService.getKey()); failed.append(" : "); failed.append(aService.getValue()); } LOG.severe(failed.toString()); } return -1; } return Module.START_OK; } /** * {@inheritDoc} * <p/> * This method loads and initializes all of the peer group modules * described in the provided implementation advertisement. Then, all modules * are placed in a list and the list is processed iteratively. During each * iteration, the {@link Module#startApp(String[])} method of each module * is invoked once. Iterations continue until no progress is being made or * the list is empty. * <p/> * The status returned by the {@link Module#startApp(String[])} method * of each module is considered as follows: * <p/> * <ul> * <li>{@link Module#START_OK}: The module is removed from the list of * modules to be started and its {@link Module#startApp(String[])} * method will not be invoked again. * </li> * <p/> * <li>{@link Module#START_AGAIN_PROGRESS}: The module remains in the * list of modules to be started and its {@link Module#startApp(String[])} * method will be invoked during the next iteration, if there is one. </li> * <p/> * <li>{@link Module#START_AGAIN_STALLED}: The module remains in the list * of modules to be started and its {@link Module#startApp(String[])} * method will be invoked during the next iteration if there is one. </li> * <p/> * <li>Any other value: The module failed to initialize. Its * {@link Module#startApp(String[])} method will not be invoked again.</li> * </ul> * <p/> * Iterations through the list stop when: * <ul> * <li>The list is empty: the group initialization proceeds.</li> * <p/> * <li>A complete iteration was performed and all modules returned * {@link Module#START_AGAIN_STALLED}: a {@link PeerGroupException} * is thrown.</li> * <p/> * <li>A number of complete iteration completed without any module * returning {@link Module#START_OK}: a {@link PeerGroupException} * is thrown. The number of complete iterations before that happens is * computed as 1 + the square of the number of modules currently in the * list.</li> * </ul> */ @Override protected synchronized void initFirst(PeerGroup parent, ID assignedID, Advertisement impl) throws PeerGroupException { if (initComplete) { if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) { LOG.warning("You cannot initialize a PeerGroup more than once !"); } return; } // Set-up the minimal GenericPeerGroup super.initFirst(parent, assignedID, impl); // assignedID might have been null. It is now the peer group ID. assignedID = getPeerGroupID(); // initialize cm before starting services. try { cm = new Cm(getHomeThreadGroup(), getStoreHome(), assignedID.getUniqueValue().toString(), Cm.DEFAULT_GC_MAX_INTERVAL, false); } catch (Exception e) { if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Error during creation of local store", e); } throw new PeerGroupException("Error during creation of local store", e); } // flush srdi for this group SrdiIndex.clearSrdi(this); // Load the list of peer group services from the impl advertisement params. StdPeerGroupParamAdv paramAdv = new StdPeerGroupParamAdv(implAdvertisement.getParam()); Map<ModuleClassID, Object> initServices = new HashMap<ModuleClassID, Object>(paramAdv.getServices()); initServices.putAll(paramAdv.getProtos()); // Remove the modules disabled in the configuration file. ConfigParams conf = getConfigAdvertisement(); if(null != conf) { Iterator<ModuleClassID> eachModule = initServices.keySet().iterator(); while(eachModule.hasNext()) { ModuleClassID aModule = eachModule.next(); if(!conf.isSvcEnabled(aModule)) { // remove disabled module if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("Module disabled in configuration : " + aModule); } eachModule.remove(); } } } // We Applications are shelved until startApp() applications.putAll(paramAdv.getApps()); if(null != conf) { Iterator<ModuleClassID> eachModule = applications.keySet().iterator(); while(eachModule.hasNext()) { ModuleClassID aModule = eachModule.next(); if(!conf.isSvcEnabled(aModule)) { // remove disabled module if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("Application disabled in configuration : " + aModule); } eachModule.remove(); } } } loadAllModules(initServices, true); int res = startModules((Map) initServices); if(Module.START_OK != res) { throw new PeerGroupException("Failed to start peer group services. res : " + res); } // Make sure all the required services are loaded. try { checkServices(); } catch (ServiceNotFoundException e) { LOG.log(Level.SEVERE, "Missing peer group service", e); throw new PeerGroupException("Missing peer group service", e); } /* * Publish a few things that have not been published in this * group yet. */ DiscoveryService discoveryService = getDiscoveryService(); if (discoveryService != null) { // It should work but if it does not we can survive. try { // Discovery service adv could not be published localy, // since at that time there was no local discovery to // publish to. discoveryService.publish(discoveryService.getImplAdvertisement(), DEFAULT_LIFETIME, DEFAULT_EXPIRATION); // Try to publish our impl adv within this group. (it was published // in the parent automatically when loaded. discoveryService.publish(implAdvertisement, DEFAULT_LIFETIME, DEFAULT_EXPIRATION); } catch (Exception nevermind) { if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) { LOG.log(Level.WARNING, "Failed to publish Impl adv within group.", nevermind); } } } } /** * {@inheritDoc} * <p/> * Nothing special for now, but we might want to move some steps from * initFirst() in the future. */ @Override protected synchronized void initLast() throws PeerGroupException { super.initLast(); if (Logging.SHOW_CONFIG && LOG.isLoggable(Level.CONFIG)) { StringBuilder configInfo = new StringBuilder("Configuring Group : " + getPeerGroupID()); configInfo.append("\n\tConfiguration :"); configInfo.append("\n\t\tCompatibility Statement :\n\t\t\t"); StringBuilder indent = new StringBuilder(STD_COMPAT.toString().trim()); int from = indent.length(); while (from > 0) { int returnAt = indent.lastIndexOf("\n", from); from = returnAt - 1; if ((returnAt >= 0) && (returnAt != indent.length())) { indent.insert(returnAt + 1, "\t\t\t"); } } configInfo.append(indent); Iterator eachProto = messageTransports.entrySet().iterator(); if (eachProto.hasNext()) { configInfo.append("\n\t\tMessage Transports :"); } while (eachProto.hasNext()) { Map.Entry anEntry = (Map.Entry) eachProto.next(); ModuleClassID aMCID = (ModuleClassID) anEntry.getKey(); Module anMT = (Module) anEntry.getValue(); configInfo.append("\n\t\t\t").append(aMCID).append("\t").append( (anMT instanceof MessageTransport) ? ((MessageTransport) anMT).getProtocolName() : anMT.getClass().getName()); } Iterator<Map.Entry<ModuleClassID, Object>> eachApp = applications.entrySet().iterator(); if (eachApp.hasNext()) { configInfo.append("\n\t\tApplications :"); } while (eachApp.hasNext()) { Map.Entry<ModuleClassID, Object> anEntry = eachApp.next(); ModuleClassID aMCID = anEntry.getKey(); Object anApp = anEntry.getValue(); if (anApp instanceof ModuleImplAdvertisement) { ModuleImplAdvertisement adv = (ModuleImplAdvertisement) anApp; configInfo.append("\n\t\t\t").append(aMCID).append("\t").append(adv.getCode()); } else { configInfo.append("\n\t\t\t").append(aMCID).append("\t").append(anApp.getClass().getName()); } } LOG.config(configInfo.toString()); } } /** * {@inheritDoc} * <p/> * FIXME 20070801 bondolo To improve compatibility with existing * applications the returned {@code ModuleImplAdvertisement} will contain * embedded {@code ModuleImplAdvertisement}s for the referenced services as * opposed to {@code ModuleSpecID}s. This is because JXSE 2.4.1 and earlier * do not handle load failures of modules loaded by spec id correctly. * After JXSE 2.5 is released this should be changed to use the better * {@code ModuleSpecID} based peer group module specification. */ // @Override public ModuleImplAdvertisement getAllPurposePeerGroupImplAdvertisement() { JxtaLoader loader = getJxtaLoader(); // grab an impl adv ModuleImplAdvertisement implAdv = loader.findModuleImplAdvertisement(PeerGroup.allPurposePeerGroupSpecID); return implAdv; } /** * Returns the cache manager associated with this group. * * @return the cache manager associated with this group. */ public Cm getCacheManager() { return cm; } /** * Return a map of the applications for this group. * <p/> * <ul> * <li>keys are {@link net.jxta.platform.ModuleClassID}</li> * <li>values are {@link net.jxta.platform.Module} or * {@link net.jxta.protocol.ModuleImplAdvertisement}</li> * </ul> * * @return a map of the applications for this group. */ public Map<ModuleClassID, Object> getApplications() { return Collections.unmodifiableMap(applications); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -