MiGenContext.java :  » Math » migen » uk » ac » lkl » migen » system » Java Open Source

Java Open Source » Math » migen 
migen » uk » ac » lkl » migen » system » MiGenContext.java
package uk.ac.lkl.migen.system;

import uk.ac.lkl.migen.system.server.MiGenServerCommunicator;

/**
 * A context in MiGen contains information about the 
 * MiGenServerCommunicator. 
 * 
 * @author sergut
 *
 */
public class MiGenContext {
    /**
     * To communicate with the server. 
     * 
     * There is one and only one
     * since the system is started until the JVM is closed.
     */
    private static MiGenServerCommunicator serverCommunicator;
    
    /**
     * Returns the MiGenServerCommunicator for this context 
     * 
     * @return the MiGenServerCommunicator for this context
     */
    public static MiGenServerCommunicator getServerCommunicator() {
  if (serverCommunicator == null || !serverCommunicator.isEnabled())
      return null;

        return serverCommunicator;
    }

    /**
     * Convenience method that returns true if the server communicator is
     * set and enabled, and false otherwise.
     * 
     * @return true if the server communicator is set and enabled, and false otherwise.
     */
    public static boolean isServerCommunicatorEnabled() {
  if (serverCommunicator == null)
      return false;
  
  return serverCommunicator.isEnabled();
    }
    
    public static void setServerCommunicator(MiGenServerCommunicator msc) {
  if (serverCommunicator != null)
      throw new IllegalStateException("The server communicator cannot be set twice.");

  if (msc == null) 
      throw new IllegalArgumentException("The server communicator cannot be set to null.");
  
  serverCommunicator = msc;
    }
    
    private MiGenContext() {
  // Cannot be instantiated by external parties
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.