All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hcl.domino.server.RunJavaAddin Maven / Gradle / Ivy

There is a newer version: 1.44.0
Show newest version
/*
 * ==========================================================================
 * Copyright (C) 2019-2022 HCL America, Inc. ( http://www.hcl.com/ )
 *                            All rights reserved.
 * ==========================================================================
 * Licensed under the  Apache License, Version 2.0  (the "License").  You may
 * not use this file except in compliance with the License.  You may obtain a
 * copy of the License at .
 *
 * Unless  required  by applicable  law or  agreed  to  in writing,  software
 * distributed under the License is distributed on an  "AS IS" BASIS, WITHOUT
 * WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the  specific language  governing permissions  and limitations
 * under the License.
 * ==========================================================================
 */
package com.hcl.domino.server;

import com.hcl.domino.DominoClient;
import com.hcl.domino.DominoClientBuilder;
import com.hcl.domino.DominoProcess;
import com.hcl.domino.DominoProcess.DominoThreadContext;
import com.hcl.domino.mq.MessageQueue;

/**
 * This base class can be extended to implement a server addin compatible
 * with {@code runjava}.
 *
 * @author Jesse Gallagher
 * @since 1.0.11
 */
public abstract class RunJavaAddin extends Thread {

  private final String addinName;
  private final String queueName;

  /**
   * Initializes the addin with the provided name, which is also
   * used as the message-queue name.
   *
   * @param addinName the name of the addin to show in the task list
   */
  public RunJavaAddin(final String addinName) {
    this(addinName, addinName);
  }

  /**
   * Initializes the addin with the provided name and message-queue name
   *
   * @param addinName the name of the addin to show in the task list
   * @param queueName the name of the queue to create
   */
  public RunJavaAddin(final String addinName, final String queueName) {
    if (addinName == null || addinName.isEmpty()) {
      throw new IllegalArgumentException("addinName cannot be empty");
    }
    if (queueName == null || queueName.isEmpty()) {
      throw new IllegalArgumentException("queueName cannot be empty");
    }

    this.addinName = addinName;
    this.queueName = queueName;
  }

  @Override
  public final void run() {
    DominoProcess.get().initializeProcess(new String[0]);
    try (DominoThreadContext ctx = DominoProcess.get().initializeThread()) {
      try (DominoClient client = DominoClientBuilder.newDominoClient().asIDUser().withFullAccess().build()) {
        try (ServerStatusLine line = client.getServerAdmin().createServerStatusLine(this.addinName)) {
          line.setLine("Running");
          try (MessageQueue queue = client.getMessageQueues().open("MQ$" + this.queueName.toUpperCase(), true)) { //$NON-NLS-1$
            this.runAddin(client, line, queue);
            System.gc();
          } catch (final Exception e) {
            e.printStackTrace();
          }
        }
      }
    } finally {
      System.gc();
      DominoProcess.get().terminateProcess();
    }

  }

  protected abstract void runAddin(DominoClient client, ServerStatusLine statusLine, MessageQueue queue);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy