/**
  * Creates a new instance. This can't be called outside of container b/c agents have no refs to
  * the singleton container. So we can be sure this method is going to create services just once.
  *
  * @param c Reference to the container.
  * @return The sole instance.
  * @throws NullPointerException If the reference to the {@link Container} is <code>null</code>.
  */
 public static PixelsServicesFactory getInstance(Container c) {
   if (c == null) throw new NullPointerException(); // An agent called this method?
   if (singleton == null) {
     registry = c.getRegistry();
     singleton = new PixelsServicesFactory();
     // Retrieve the maximum heap size.
     MemoryUsage usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
     String message = "Heap memory usage: max " + usage.getMax();
     registry.getLogger().info(singleton, message);
     // percentage of memory used for caching.
     maxSize = (int) (RATIO * usage.getMax()) / FACTOR;
   }
   return singleton;
 }
  /**
   * Checks if the rendering controls are still active. Shuts the inactive ones.
   *
   * @param context Reference to the registry. To ensure that agents cannot call the method. It must
   *     be a reference to the container's registry.
   */
  public static void checkRenderingControls(Registry context) {
    // TODO Auto-generated method stub
    if (!(context.equals(registry)))
      throw new IllegalArgumentException("Not allow to access method.");
    RenderingControlProxy proxy;
    Entry<Long, RenderingControl> e;
    Iterator<Entry<Long, RenderingControl>> i = singleton.rndSvcProxies.entrySet().iterator();
    Long value = (Long) context.lookup(LookupNames.RE_TIMEOUT);

    long timeout = 60000; // 1min
    if (value != null && value.longValue() > timeout) timeout = value.longValue();

    Logger logger = context.getLogger();
    while (i.hasNext()) {
      e = i.next();
      proxy = (RenderingControlProxy) e.getValue();
      if (!proxy.isProxyActive(timeout)) {
        if (!proxy.shutDown(true))
          logger.info(singleton, "Rendering Engine shut down: PixelsID " + e.getKey());
      }
    }
  }
Exemplo n.º 3
0
  /**
   * Sets the file to edit. If the file cannot be read by {@link TreeModelFactory#getTree()} then
   * the state of this model is re-set to {@link Editor#NEW}.
   *
   * @param file The file to edit.
   * @return See above.
   */
  boolean setFileToEdit(File file) {
    if (file == null) {
      fileToEdit = null;
      state = Editor.NEW;
      fileName = EditorFactory.BLANK_MODEL;
      return false;
    }
    TreeModel treeModel = null;

    // try opening file as recognised OMERO.editor file (pro.xml or cpe.xml)
    try {
      treeModel = TreeModelFactory.getTree(file);
      fileToEdit = file;
    } catch (ParsingException e) {

      // may get a parsing exception simply because the file was not
      // recognised as Editor File..

      Registry reg = EditorAgent.getRegistry();
      UserNotifier un = reg.getUserNotifier();

      // ... try opening as ANY xml file
      try {
        treeModel = TreeModelFactory.getTreeXml(file);
        // if this worked, we have an XML file converted to cpe.xml
        // .. tell user..
        un.notifyInfo(
            "File not recognised",
            "File was converted from an unrecognised format into\n"
                + "OMERO.editor's cpe.xml format.\nOverwriting the "
                + "original file will erase the original XML format.");
        // must avoid overwriting the original file...
        // 'Save' won't work.
        if (fileID > 0) { // try to read a file downloaded
          file.delete();
        }
        fileToEdit = null;
        setFileAnnotationData(null);

      } catch (ParsingException ex) {

        LogMessage message = new LogMessage();
        message.print(ex);
        reg.getLogger().error(this, message);

        // ...and notify the user. Use the exception message.
        String errMsg = ex.getMessage();
        un.notifyInfo("File Failed to Open", errMsg);
      }
    }

    if (treeModel == null) {
      fileToEdit = null;
      state = Editor.NEW;
      fileName = EditorFactory.BLANK_MODEL;
      return false;
    }

    fileName = file.getName();
    browser.setTreeModel(treeModel);
    state = Editor.READY;
    return true;
  }