📄 stdpeergroup.java
字号:
while (eachModule.hasNext()) { Map.Entry anEntry = (Map.Entry) eachModule.next(); m = (Module) anEntry.getValue(); int res; try { res = m.startApp(null); } catch ( Throwable all ) { if (LOG.isEnabledFor(Level.ERROR)) { LOG.error("Exception in startApp() : " + m, all ); } res = -1; } switch (res) { case Module.START_OK: // One done. Remove from allStart and recompute maxIteration. if (LOG.isEnabledFor(Level.INFO)) { LOG.info("Module started : " + m); } eachModule.remove(); --modulesToGo; maxIterations = modulesToGo * modulesToGo + 1; case Module.START_AGAIN_PROGRESS: progress = true; case Module.START_AGAIN_STALLED: break; default: // (negative) if (LOG.isEnabledFor(Level.WARN)) { LOG.warn( "Module failed to start (" + res + ") : " + m ); } eachModule.remove(); --modulesToGo; maxIterations = modulesToGo * modulesToGo + 1; // remove the module from the service tables. we don't // know which table its in unfortunately. try { if( m instanceof Service ) removeService( (ModuleClassID) anEntry.getKey(), (Service) m ); } catch ( ServiceNotFoundException ignored ) {;} catch ( ViolationException ignored ) {;} protocols.remove( anEntry.getKey() ); break; } } } // Uh-oh. Services co-dependency prevented them from starting. if (allStart.size() > 0) { if (LOG.isEnabledFor(Level.ERROR)) { StringBuffer failed = new StringBuffer( "No progress is being made in starting services. Giving up." ); failed.append( "\nThe following services refused to start: " ); Iterator sequence = allStart.values().iterator(); while (sequence.hasNext()) { failed.append( "\n\t" ); failed.append( sequence.next().toString() ); } LOG.error( failed ); } throw new PeerGroupException("No progress is being made in starting services. Giving up."); } // Make sure all the required services are loaded. try { checkServices(); } catch (ServiceNotFoundException e) { LOG.fatal( "Missing peer group service", e ); throw new PeerGroupException( "Missing peer group service", e ); } catch ( Throwable e) { LOG.fatal( "Unhandled Throwable", e ); throw new PeerGroupException( "Unhandled Throwable", e ); } /* * Publish a few things that have not been published in this * group yet. */ DiscoveryService disco = getDiscoveryService(); if (disco != 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. FIXME: this is really a cherry on the cake. // no-one realy cares disco.publish(disco.getImplAdvertisement(), DEFAULT_LIFETIME, DEFAULT_EXPIRATION); // Try to publish our impl adv within this group. (it was published // in the parent automatically when loaded. disco.publish(implAdv, DEFAULT_LIFETIME, DEFAULT_EXPIRATION); } catch(Exception nevermind) { if (LOG.isEnabledFor(Level.WARN)) LOG.warn( "Failed to publish Impl adv within group.", nevermind ); } } initialized = true; } /** * {@inheritDoc} */ protected synchronized void initLast() throws PeerGroupException { // Nothing special for now, but we might want to move some steps // from initFirst, in the future. super.initLast(); if (LOG.isEnabledFor(Level.INFO)) { StringBuffer configInfo = new StringBuffer("Configuring Group : " + getPeerGroupID()); configInfo.append("\n\tConfiguration :"); configInfo.append("\n\t\tCompatibility Statement :\n\t\t\t" ); StringBuffer indent = new StringBuffer( 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 = protocols.entrySet().iterator(); if( eachProto.hasNext() ) { configInfo.append("\n\t\tProtocols :"); } 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" + aMCID + "\t"+ ((anMT instanceof MessageTransport) ? ((MessageTransport)anMT).getProtocolName() : anMT.getClass().getName()) ); } Iterator eachApp = applications.entrySet().iterator(); if(eachApp.hasNext() ) { configInfo.append("\n\t\tApplications :"); } while (eachApp.hasNext()) { Map.Entry anEntry = (Map.Entry) eachApp.next(); ModuleClassID aMCID = (ModuleClassID) anEntry.getKey(); Object anApp = anEntry.getValue(); if( anApp instanceof ModuleImplAdvertisement ) { ModuleImplAdvertisement adv = (ModuleImplAdvertisement) anApp; configInfo.append( "\n\t\t\t" + aMCID + "\t"+ adv.getCode() ); } else { configInfo.append( "\n\t\t\t" + aMCID + "\t"+ anApp.getClass().getName() ); } } LOG.info(configInfo); } } /** * {@inheritDoc} **/ public ModuleImplAdvertisement getAllPurposePeerGroupImplAdvertisement() { // Build it only the first time; then clone it. if (allPurposeImplAdv != null) return (ModuleImplAdvertisement) allPurposeImplAdv.clone(); // grab an impl adv ModuleImplAdvertisement implAdv = mkImplAdvBuiltin( PeerGroup.allPurposePeerGroupSpecID, StdPeerGroup.class.getName(), "General Purpose Peer Group Implementation"); TextElement paramElement = (TextElement) implAdv.getParam(); StdPeerGroupParamAdv paramAdv = new StdPeerGroupParamAdv( ); ModuleImplAdvertisement moduleAdv; // set the services Hashtable services = new Hashtable(); // core services moduleAdv = mkImplAdvBuiltin(PeerGroup.refEndpointSpecID, "net.jxta.impl.endpoint.EndpointServiceImpl", "Reference Implementation of the Endpoint service"); services.put(PeerGroup.endpointClassID, moduleAdv); moduleAdv = mkImplAdvBuiltin(PeerGroup.refResolverSpecID, "net.jxta.impl.resolver.ResolverServiceImpl", "Reference Implementation of the Resolver service"); services.put(PeerGroup.resolverClassID, moduleAdv); moduleAdv = mkImplAdvBuiltin(PeerGroup.refMembershipSpecID, "net.jxta.impl.membership.none.NoneMembershipService", "Reference Implementation of the None Membership service"); services.put(PeerGroup.membershipClassID, moduleAdv); moduleAdv = mkImplAdvBuiltin(refAccessSpecID, "net.jxta.impl.access.always.AlwaysAccessService", "Reference Implementation of the Always Access service"); services.put(PeerGroup.accessClassID, moduleAdv); // standard services moduleAdv = mkImplAdvBuiltin(PeerGroup.refDiscoverySpecID, "net.jxta.impl.discovery.DiscoveryServiceImpl", "Reference Implementation of the Discovery service"); services.put(PeerGroup.discoveryClassID, moduleAdv); moduleAdv = mkImplAdvBuiltin(PeerGroup.refRendezvousSpecID, "net.jxta.impl.rendezvous.RendezVousServiceImpl", "Reference Implementation of the Rendezvous service"); services.put(PeerGroup.rendezvousClassID, moduleAdv); moduleAdv = mkImplAdvBuiltin(PeerGroup.refPipeSpecID, "net.jxta.impl.pipe.PipeServiceImpl", "Reference Implementation of the Pipe service" ); services.put(PeerGroup.pipeClassID, moduleAdv); moduleAdv = mkImplAdvBuiltin(PeerGroup.refPeerinfoSpecID, "net.jxta.impl.peer.PeerInfoServiceImpl", "Reference Implementation of the Peerinfo service" ); services.put( PeerGroup.peerinfoClassID, moduleAdv ); paramAdv.setServices(services); // NO Transports. Hashtable protos = new Hashtable(); paramAdv.setProtos(protos); // Main app is the shell // Build a ModuleImplAdv for the shell ModuleImplAdvertisement newAppAdv = (ModuleImplAdvertisement) AdvertisementFactory.newAdvertisement( ModuleImplAdvertisement.getAdvertisementType()); // The shell's spec id is a canned one. newAppAdv.setModuleSpecID(PeerGroup.refShellSpecID); // Same compat than the group. newAppAdv.setCompat(implAdv.getCompat()); newAppAdv.setUri(implAdv.getUri()); newAppAdv.setProvider(implAdv.getProvider()); // Make up a description newAppAdv.setDescription("JXTA Shell Reference Implementation"); // Tack in the class name newAppAdv.setCode( "net.jxta.impl.shell.bin.Shell.Shell" ); // Put that in a new table of Apps and replace the entry in // paramAdv Hashtable newApps = new Hashtable(); newApps.put(PeerGroup.applicationClassID, newAppAdv); paramAdv.setApps(newApps); // Pour our newParamAdv in implAdv paramElement = (TextElement) paramAdv.getDocument(MimeMediaType.XMLUTF8); implAdv.setParam(paramElement); allPurposeImplAdv = implAdv; return (ModuleImplAdvertisement) implAdv.clone(); } /** * Returns the cache manager associated with this group. * * @return the cache manager associated with this group. **/ public Cm getCacheManager() { return cm; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -