📄 genericpeergroup.java
字号:
return; } if (!stopWhenUnreferenced) { return; } } if (LOG.isEnabledFor(Level.INFO)) { LOG.info("[" + getPeerGroupID() + "] STOPPING UNREFERENCED GROUP" ); } stopApp(); masterRefCount = Integer.MIN_VALUE; } /* * Implement the Service API so that we can make groups services when we * decide to. */ /** * {@inheritDoc} **/ public Service getInterface() { synchronized (this) { ++masterRefCount; if( masterRefCount < 1 ) { throw new IllegalStateException( "Group has been shutdown. getInterface() is not available"); } if (LOG.isEnabledFor(Level.INFO)) { Throwable trace = new Throwable( "Stack Trace" ); StackTraceElement elements[] = trace.getStackTrace(); LOG.info("[" + getPeerGroupID() + "] GROUP REF COUNT INCREMENTED TO: " + masterRefCount + " by\n\t" + elements[2] ); } if (initComplete) { // If init is complete the group can become sensitive to // its ref count reaching zero. Before there could be // transient references before there is a chance to give // a permanent reference to the invoker of newGroup. stopWhenUnreferenced = true; } } return new RefCountPeerGroupInterface(this); } /** * {@inheritDoc} **/ public PeerGroup getWeakInterface() { return new PeerGroupInterface(this); } /** * {@inheritDoc} **/ public Advertisement getImplAdvertisement() { return (Advertisement) implAdvertisement.clone(); } /** * {@inheritDoc} **/ public void publishGroup(String name, String description) throws IOException { if (published) { return; } peerGroupAdvertisement.setName(name); peerGroupAdvertisement.setDescription(description); if (parentGroup == null) { return; } DiscoveryService parentDiscovery = parentGroup.getDiscoveryService(); if( null == parentDiscovery ) { return; } parentDiscovery.publish(peerGroupAdvertisement, DEFAULT_LIFETIME, DEFAULT_EXPIRATION); published = true; } /** * {@inheritDoc} **/ public PeerGroup newGroup(Advertisement pgAdv) throws PeerGroupException { PeerGroupAdvertisement adv = (PeerGroupAdvertisement) pgAdv; PeerGroupID gid = adv.getPeerGroupID(); if ((gid == null) || ID.nullID.equals(gid)) { throw new IllegalArgumentException("Advertisement did not contain a peer group ID"); } PeerGroup theNewGroup = globalRegistry.lookupInstance(gid); if (theNewGroup != null) { return theNewGroup; } // We do not know if the grp adv had been previously published or not... Since it may contain information essential to // the configuration of services, we need to make sure it is published localy, rather than letting the group publish // itself after the fact. // FIXME jice@jxta.org 20040713 : The downside is that we're publishing the adv even before making sure that this group // can really be instantiated. We're basically using the cm as a means to pass parameters to the module because it is a // group. We have the same parameter issue with the config adv. Eventually we need to find a clean way of passing // parameters specific to a certain types of module. try { discovery.publish(adv, DEFAULT_LIFETIME, DEFAULT_EXPIRATION); } catch (Exception any) { if (LOG.isEnabledFor(Level.WARN)) { LOG.warn("Could not publish the group advertisement: ", any); } } theNewGroup = (PeerGroup) loadModule( adv.getPeerGroupID(), adv.getModuleSpecID(), Here, false); if (theNewGroup == null) { throw new PeerGroupException( "Could not find group implementation with " + adv.getModuleSpecID() ); } return (PeerGroup) theNewGroup.getInterface(); } /** * {@inheritDoc} **/ public PeerGroup newGroup(PeerGroupID gid, Advertisement impl, String name, String description) throws PeerGroupException { PeerGroup theNewGroup = null; if (null != gid) { theNewGroup = globalRegistry.lookupInstance(gid); } if (theNewGroup != null) { return theNewGroup; } try { theNewGroup = (PeerGroup) loadModule(gid, (ModuleImplAdvertisement) impl, false); } catch (Throwable any) { if (LOG.isEnabledFor(Level.ERROR)) { LOG.error( "Could not load group implementation", any ); } throw new PeerGroupException( "Could not load group implementation", any ); } try { // The group adv definitely needs to be published. theNewGroup.publishGroup(name, description); } catch (Exception any) { if (LOG.isEnabledFor(Level.WARN)) { LOG.warn( "Could not publish group or implementation:", any ); } } return (PeerGroup) theNewGroup.getInterface(); } /** * {@inheritDoc} **/ public PeerGroup newGroup(PeerGroupID gid) throws PeerGroupException { if ((gid == null) || ID.nullID.equals(gid)) { throw new IllegalArgumentException("Invalid peer group ID"); } PeerGroup result = globalRegistry.lookupInstance(gid); if (result != null) { return result; } PeerGroupAdvertisement adv; try { adv = (PeerGroupAdvertisement) discoverOne(DiscoveryService.GROUP, "GID", gid.toString(), 120, PeerGroupAdvertisement.class ); } catch ( Throwable any ) { throw new PeerGroupException( "Failed finding group advertisement for " + gid, any ); } if (adv == null) { throw new PeerGroupException("Could not find group advertisement for group " + gid ); } return newGroup( adv ); } /** * {@inheritDoc} **/ public JxtaLoader getLoader() { return loader; } /** * {@inheritDoc} **/ public String getPeerName() { // before init we must fail. if(null == peerAdvertisement) { throw new IllegalStateException( "PeerGroup not sufficiently initialized" ); } return peerAdvertisement.getName(); } /** * {@inheritDoc} **/ public String getPeerGroupName() { // before init we must fail. if(null == peerGroupAdvertisement) { throw new IllegalStateException( "PeerGroup not sufficiently initialized" ); } return peerGroupAdvertisement.getName(); } /** * {@inheritDoc} **/ public PeerGroupID getPeerGroupID() { // before init we must fail. if(null == peerGroupAdvertisement) { throw new IllegalStateException( "PeerGroup not sufficiently initialized" ); } return peerGroupAdvertisement.getPeerGroupID(); } /** * {@inheritDoc} **/ public PeerID getPeerID() { // before init we must fail. if(null == peerAdvertisement) { throw new IllegalStateException( "PeerGroup not sufficiently initialized" ); } return peerAdvertisement.getPeerID(); } /** * {@inheritDoc} **/ public PeerAdvertisement getPeerAdvertisement() { return peerAdvertisement; } /** * {@inheritDoc} **/ public PeerGroupAdvertisement getPeerGroupAdvertisement() { return peerGroupAdvertisement; } /** * {@inheritDoc} **/ public boolean isRendezvous() { if (rendezvous == null) { if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("Rendezvous service null"); } } return (rendezvous != null) && rendezvous.isRendezVous(); } /* * shortcuts to the well-known services, in order to avoid calls to lookup. */ /** * {@inheritDoc} **/ public EndpointService getEndpointService() { if (endpoint == null) { return null; } return (EndpointService) endpoint.getInterface(); } /** * {@inheritDoc} **/ public ResolverService getResolverService() { if (resolver == null) { return null; } return (ResolverService) resolver.getInterface(); } /** * {@inheritDoc} **/ public DiscoveryService getDiscoveryService() { if (discovery == null) { return null; } return (DiscoveryService) discovery.getInterface(); } /** * {@inheritDoc} **/ public PeerInfoService getPeerInfoService() { if (peerinfo == null) { return null; } return (PeerInfoService) peerinfo.getInterface(); } /** * {@inheritDoc} **/ public MembershipService getMembershipService() { if (membership == null) { return null; } return (MembershipService) membership.getInterface(); } /** * {@inheritDoc} **/ public PipeService getPipeService() { if (pipe == null) { return null; } return (PipeService) pipe.getInterface(); } /** * {@inheritDoc} **/ public RendezVousService getRendezVousService() { if (rendezvous == null) { return null; } return (RendezVousService) rendezvous.getInterface(); } /** * {@inheritDoc} **/ public AccessService getAccessService() { if (access == null) { return null; } return (AccessService) access.getInterface(); } /** * {@inheritDoc} **/ public abstract ModuleImplAdvertisement getAllPurposePeerGroupImplAdvertisement(); /** * {@inheritDoc} * * <p/>We do not want to count on the invoker to properly unreference * the group object that we return; this call is often used in a * loop and it is silly to increment and decrement ref-counts for * references that are sure to live shorter than the referee. * On the other hand it is dangerous for us to share our reference * object to the parent group. That's where weak interface objects * come in handy. We can safely make one and give it away. */ public PeerGroup getParentGroup() { if (parentGroup == null) { return null; } return parentGroup.getWeakInterface(); } /** * {@inheritDoc} **/ public URI getStoreHome() { return jxtaHome; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -