ServerHelper.java

/*
** Module   : ServerHelper.java
** Abstract : defines common APIs for servers connected to an appserver or web service.
**
** Copyright (c) 2013-2019, Golden Code Development Corporation.
**
** -#- -I- --Date-- -------------------------------Description------------------------------------
** 001 CA  20131220 Created initial version.
** 002 CA  20150416 Added isConnected.
** 003 CA  20160404 Enhanced the appserver invocations, to allow implicit or explicit termination
**                  of requests being executing on a certain connection.
** 004 CA  20190118 disconnect() must be aware if the FWD session is gone.
** 005 CA  20190326 Added back disconnect() without arguments, to allow backwards compatibility.
** 006 CA  20190628 Added invoke() API which uses a InvokeConfig instance.
*/
/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Affero General Public License for more details.
**
** You may find a copy of the GNU Affero GPL version 3 at the following
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
** 
** Additional terms under GNU Affero GPL version 3 section 7:
** 
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
**   terms apply to the works covered under the License.  These additional terms
**   are non-permissive additional terms allowed under Section 7 of the GNU
**   Affero GPL version 3 and may not be removed by you.
** 
**   0. Attribution Requirement.
** 
**     You must preserve all legal notices or author attributions in the covered
**     work or Appropriate Legal Notices displayed by works containing the covered
**     work.  You may not remove from the covered work any author or developer
**     credit already included within the covered work.
** 
**   1. No License To Use Trademarks.
** 
**     This license does not grant any license or rights to use the trademarks
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
**     of Golden Code Development Corporation. You are not authorized to use the
**     name Golden Code, FWD, or the names of any author or contributor, for
**     publicity purposes without written authorization.
** 
**   2. No Misrepresentation of Affiliation.
** 
**     You may not represent yourself as Golden Code Development Corporation or FWD.
** 
**     You may not represent yourself for publicity purposes as associated with
**     Golden Code Development Corporation, FWD, or any author or contributor to
**     the covered work, without written authorization.
** 
**   3. No Misrepresentation of Source or Origin.
** 
**     You may not represent the covered work as solely your work.  All modified
**     versions of the covered work must be marked in a reasonable way to make it
**     clear that the modified work is not originating from Golden Code Development
**     Corporation or FWD.  All modified versions must contain the notices of
**     attribution required in this license.
*/

package com.goldencode.p2j.util;

/**
 * Defines common APIs used by a server connected to either an appserver or a web service.
 */
public abstract class ServerHelper
{
   /** The {@link ServerImpl} instance associated with this helper. */
   protected ServerImpl server;

   /**
    * Get the name of this server.
    * 
    * @return   See above.
    */
   public abstract String getServerName();

   /**
    * Get the sub-type of this server.
    * 
    * @return   See above.
    */
   public abstract String getSubType();

   /**
    * Get the connection ID.
    * 
    * @return   See above.
    */
   public abstract String getConnectionID();
   
   /**
    * Check if this is a web service.
    * 
    * @return   <code>true</code> if we are connected to a web service.
    */
   public abstract boolean isWebService();
   
   /**
    * Check if this is a session-free connection.
    * 
    * @return   <code>true</code> if this is a session-free connection.
    */
   public abstract boolean isSessionFree();
   
   /**
    * Disconnect this server.
    * 
    * @param    disconnecting
    *           Flag indicating if the FWD client session is being terminated.
    */
   public abstract void disconnect(boolean disconnecting);
   
   /**
    * Check if the connection is still established.
    * 
    * @return   <code>true</code> if the server is currently connected.
    */
   public abstract boolean isConnected();
   
   /**
    * Send a STOP condition to the specified async request.
    * 
    * @param    requestId
    *           The request where to send a STOP condition.
    */
   public abstract void sendStop(int requestId);
   
   /**
    * Send a STOP condition to the request(s) currently being executed on this connection.
    */
   public abstract void sendStop();

   /**
    * Invoke a remote external procedure, internal procedure, user-defined function or web service
    * operation. The validation for the name and arguments will be specific to the established 
    * server connection subtype.
    * 
    * @param    timeout
    *           The maximum allowed time for this invocation to complete.  In milliseconds.
    *           Use <code>0</code> to disable the timeout.
    * @param    name
    *           The legacy 4GL name for the procedure/function.
    * @param    h
    *           The persistent procedure in which to invoke the internal procedure, function or
    *           operation.
    * @param    function
    *           <code>true</code> if this is a function call.
    * @param    dynamicFunction
    *           <code>true</code> if this is a DYNAMIC-FUNCTION call.
    * @param    superCall
    *           <code>true</code> if this is a RUN SUPER or SUPER() call.
    * @param    transactionDistinct
    *           Flag indicating if the TRANSACTION DISTINCT clause is in effect.
    * @param    modes
    *           A string representation of the modes of each parameter. The modes may be mandatory 
    *           for a specific implementation.
    * @param    args
    *           The procedure's arguments.
    * 
    * @return   The result of this procedure/function invocation or <code>null</code> if the
    *           invocation could not be performed.
    */
   abstract BaseDataType invoke(long             timeout,
                                AsyncRequestImpl asyncReq,
                                character        name,
                                handle           h,
                                boolean          function,
                                boolean          dynamicFunction,
                                boolean          superCall,
                                boolean          transactionDistinct,
                                String           modes,
                                Object...        args);
   
   /**
    * Invoke a remote external procedure, internal procedure, user-defined function or web service
    * operation. The validation for the name and arguments will be specific to the established 
    * server connection subtype.
    * 
    * @param    timeout
    *           The maximum allowed time for this invocation to complete.  In milliseconds.
    *           Use <code>0</code> to disable the timeout.
    * @param    asyncReq
    *           When not-null, an {@link AsyncRequestImpl} instance for the associated async
    *           request.
    * @param    cfg
    *           The invoke configuration.
    *           
    * @return   The result of this procedure/function invocation or <code>null</code> if the
    *           invocation could not be performed.
    */
   abstract BaseDataType invoke(long timeout, AsyncRequestImpl asyncReq, InvokeConfig cfg);
   
   /**
    * Disconnect this server - this assumes the FWD connection is being terminated.
    */
   public void disconnect()
   {
      disconnect(true);
   }
   
   /**
    * Set the {@link ServerImpl} instance associated with this helper.
    * 
    * @param    server
    *           The {@link ServerImpl} instance.
    */
   void setServer(ServerImpl server)
   {
      this.server = server;
   }

   /**
    * Get the {@link #server} instance associated with this helper.
    * 
    * @return   See above.
    */
   ServerImpl getServer()
   {
      return server;
   }
}