package textbender.a.r.page; // Copyright 2007, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import java.rmi.*; import textbender.a.r.desk.*; import textbender.a.u.transfer.*; import textbender.g.hold.*; import textbender.g.lang.*; import textbender.g.util.logging.*; /** Collected communication links. */ public @ThreadSafe final class Connections { /** Constructs an instance of Connections. * * @param s spool for internal holds. When unwound, this instance * will become disabled, and will release its internal holds. * All holds are listener registrations with the desk daemon, * which automatically cleans out dead listeners anyway, * so a Spool0 is OK here. */ Connections( Spool s ) { spool = s; } // ------------------------------------------------------------------------------------ /** A client-side region-transfer hub. */ public PRTransferCHub transferCHub() { return transferCHub; } // private transient PRTransferCHub transferCHub; private volatile PRTransferCHub transferCHub; /** A reference to the service registry of the desk daemon * on the local host. * * @return reference to service registry; or null * if the latest {@linkplain #refresh connection attempt} failed */ public HostServiceRegistry hostServiceRegistry() { return hostServiceRegistry; } // private transient HostServiceRegistry hostServiceRegistry; private volatile HostServiceRegistry hostServiceRegistry; /** Refreshes all links, dropping and reforming them if dead. * Page daemons ought to call this method as part of their initialization * for each page visit or page refresh. */ public void refresh() throws RemoteException // FIX by distributing implementations of refresh for various links as RemoteRefreshable's, and invoking them from a list { // Non-atomic test/act in refresh methods, throughout. // Race is unlikely. Consequences are non-critical, // and temporary till next page refresh. HostServiceRegistry hostServiceRegistryNew = HostServiceRegistry.X.findRegistry(); if( ObjectX.nullEquals( hostServiceRegistryNew, hostServiceRegistry )) return; hostServiceRegistry = hostServiceRegistryNew; if( hostServiceRegistry != null ) LoggerX.i(getClass()).config( "new connection to desk daemon" ); transferCHub = new PRTransferCHub( hostServiceRegistry, spool ); } // ------------------------------------------------------------------------------------ private final Spool spool; }