package textbender.a.u.transfer; // Copyright 2006, 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.beans.*; import java.rmi.*; import java.rmi.server.*; import java.util.concurrent.atomic.*; import textbender.a.r.desk.*; import textbender.g.beans.*; import textbender.g.lang.*; import textbender.g.util.logging.*; /** Paired-regions transfer server implementation. */ public final class PRTransferS extends UnicastRemoteObject implements PropertyChangeListenerX.Registry, PRTransfer.Server { private static final AtomicReference instanceA = new AtomicReference(); /** Creates the single instance of PRTransferS and registers it as a service. */ public PRTransferS() throws RemoteException { if( !instanceA.compareAndSet( /*expect*/null, PRTransferS.this )) throw new IllegalStateException(); LoggerX.i(getClass()).config( "creating host service" ); HostServiceRegistry1.i().addService ( PRTransfer.Server.class, PRTransferS.this ); } // ```````````````````````````````````````````````````````````````````````````````````` // Initialized early, for use in other initializers. private final PropertyChangeSupport propertyChangeSupport // OPT for dispatch speed: use a non-thread-safe list, @ThreadRestricted("desk executor thread"). Note that SwingPropertyChangeSupport will not suit this purpose, because it is now an empty sub-class (JDK 1.5). = new PropertyChangeSupport( PRTransferS.this ); // - P r o p e r t y - C h a n g e - L i s t e n e r - R . R e g i s t r y ------------ public @ThreadSafe void addPropertyChangeListener( PropertyChangeListenerR listener ) { propertyChangeSupport.addPropertyChangeListener ( new PropertyChangeListenerR.WrapperL( listener, propertyChangeDispatchCatcher )); // LoggerX.i(getClass()).finest( "listener list at: " + propertyChangeSupport.getPropertyChangeListeners().length ); } public @ThreadSafe void disabledPropertyChangeListener( PropertyChangeListenerR listener ) { propertyChangeSupport.removePropertyChangeListener ( new PropertyChangeListenerR.WrapperL( listener, propertyChangeDispatchCatcher )); // LoggerX.i(getClass()).finest( "listener list at: " + propertyChangeSupport.getPropertyChangeListeners().length ); } // - P r o p e r t y - C h a n g e - L i s t e n e r - X . R e g i s t r y ------------ public void addPropertyChangeListener( PropertyChangeListener listener ) { propertyChangeSupport.addPropertyChangeListener( listener ); } public void removePropertyChangeListener( PropertyChangeListener listener ) { propertyChangeSupport.removePropertyChangeListener( listener ); } // - P - R - T r a n s f e r ---------------------------------------------------------- public @ThreadSafe synchronized Transferand getTransferand() { return transferand; }; private @ThreadRestricted("holds this") Transferand transferand; public @ThreadSafe synchronized void setTransferand( final Transferand newTransferand ) { // System.out.println( "PRTS newTransferand=" + newTransferand ); if( Run.i().spool().isUnwinding() ) return; PropertyChangeEventAD e = new PropertyChangeEventAD ( PRTransferS.this, "transferand", transferand, newTransferand, propertyChangeSupport ); transferand = newTransferand; DeskDaemon.i().executor().execute( e ); // enqueue in sync, for correct e order } //// P r i v a t e /////////////////////////////////////////////////////////////////////// private final PropertyChangeListenerR.DispatchCatcher propertyChangeDispatchCatcher = new PropertyChangeListenerR.DispatchCatcher( /*registry*/PRTransferS.this ); }