Server APIs

This appendix describes AnyLink user APIs, especially related to service flows and the multi-binding router.

Most of APIs described in this appendix are defined along with a default implementation user class whose name starts with 'Default'. It is recommended to implement a user interface by inheriting the class.

The MessageContext interface which is used commonly in various packages is defined.

<MessageContext>

package com.tmax.anylink.api;

/**
 * Standard interface that represents a message.
 */
public interface MessageContext {
    /**
     * Returns the data of the @return message.
     */
    Object getContent();

    /**
     * Returns the property value of the @return message.
     */
    Object getProperty(String propertyName);

    /**
     * Specifies the message's property value.
     *
     * @param propertyName, property name
     * @param propertyValue, property value
     */
    void setProperty(String propertyName, Object propertyValue);
}

Defines interfaces for user classes and handlers used in service flows' processes or activities, and their default implementation classes. For example, the interface for a user activity is defined as the UserActivity interface, and the default implementation class is defined as the DefaultUserActivity abstract class.

Interface Description

ActivityContext

Represents the execution context of an activity.

ActivityErrorHandler

Handler interface that can handle activity errors.

ActivityHandler

AnyLink activity handler interface.

BlockContext

Represents the execution context of a block activity including the currently executed activity.

ErrorCodeMapper

Converts internal errors into error code that can be recognized by the AnyLink service flow.

UserMapping

Allows the user to write data conversion code in the AnyLink service flow.

ProcessContext

Represents the execution context of the currently executed service flow.

ProcessHandler

AnyLink process handler interface.

ServiceActivityHandler

AnyLink service activity handler interface.

UserActivity

Represents the user activity.

VariableContext

Defines the interface that corresponds to the service flow variable.

It is recommended to implement a user interface by inheriting a default abstract class.

2.1. ActivityContext

Represents the execution context of an activity.

package com.tmax.anylink.api.serviceflow;

/**
 * Interface that represents the execution context of an activity
 */

public interface ActivityContext {
    /**
     * @return returns the activity ID.
     */
    String getActivityId();

    /**
     * @return returns the variable context with the specified name as seen in this activity scope.
     */
    VariableContext getVariable(String variableName);

    /**
     * @return returns the context of the service flow that contains this activity.
     */
    ProcessContext getProcessContext();

    /**
     * @return returns the context of the block activity including this activity.
     * If the block activity is not enclosed, null is returned.
     */
    BlockContext getBlockContext();
}

2.2. ActivityErrorHandler

Handler interface that can handle activity errors.

package com.tmax.anylink.api.serviceflow;

import com.tmax.anylink.common.AnyLinkException;

/**
 * Handler interface used to handle activity errors
 */

public interface ActivityErrorHandler {
    /**
     * Method called when an error occurs during the execution of an activity in which the handler is defined.
     */
    void handle(ActivityContext context, Throwable error) throws AnyLinkException;
}

2.3. ActivityHandler

AnyLink activity handler interface.

package com.tmax.anylink.api.serviceflow;

import com.tmax.anylink.common.AnyLinkException;

/**
 * AnyLink activity handler interface.
 * When an object implementing this interface is registered as a handler for the activity,
 * corresponding methods are called according to the life cycle time of the activity instance.
 */

public interface ActivityHandler {
    /**
     * Method called at the start of the activity
     */
    void started(ActivityContext ctx) throws AnyLinkException;

    /**
     * Method called at normal end of the activity
     */
    void finished(ActivityContext ctx) throws AnyLinkException;

    /**
     * Method called when an activity is canceled without being terminated.
     * An activity can be canceled for a number of reasons, usually canceled
     * by another activity or event in the service flow.
     */
    void cancelled(ActivityContext ctx, String cause) throws AnyLinkException;

    /**
     * Method called when the activity is terminated by an error
     */
    void errorOccurred(ActivityContext ctx, Throwable t) throws AnyLinkException;
}

2.4. BlockContext

Represents the execution context of a block activity including the currently executed activity.

package com.tmax.anylink.api.serviceflow;

/**
 * Interface representing the execution context of a block activity including the currently executed activity.
 */

public interface BlockContext {
    /**
     * @return returns the variable context with the specified name as seen in this block scope.
     */
    VariableContext getVariable(String variableName);

    /**
     * @return returns the execution context of the parent block activity including the block activity.
     * If there is no parent block activity, null is returned.
     */
    BlockContext getParentBlockContext();

    /**
     * @return returns the context of the service flow that contains the block activity.
     */
    ProcessContext getProcessContext();
}

2.5. ErrorCodeMapper

Converts internal errors into error code that can be recognized by the AnyLink service flow.

package com.tmax.anylink.api.serviceflow;

/**
 * Interface for converting internal errors into error code that can be recognized by the AnyLink service flow.
 * If the AnyLink service flow does not need to catch all exceptions, it needs to know the error code to handle the error.
 * This interface converts the generated Java objects into error codes so that error events in the service flow can catch them.
 */

public interface ErrorCodeMapper {
    /**
     * @param throwable, the generated Java exception object
     * @return returns the error code value to be handled by the error event of the service flow.
     */
    String getErrorCode(Throwable throwable);
}

2.6. UserMapping

Allows the user to write data conversion code in the AnyLink service flow.

package com.tmax.anylink.api.serviceflow;

/**
 * Interface that allows users to write data conversion code in the AnyLink service flow.
 * Used for request, response, abnormal response, and custom log mappings by using user-written code.
 */

public interface UserMapping {
    /**
     * User-written mapping method
     *
     * @param ctx, the current activity context
     * @param inputParams, input parameters are sent via this variable.
     * @return, the mapped result data. The number of result parameters and the array size must be the same.

     */
    Object[] mapping(ActivityContext ctx, Object[] inputParams) throws AnyLinkException;
}

2.7. ProcessContext

Represents the execution context of the currently executed service flow.

package com.tmax.anylink.api.serviceflow;

import com.tmax.anylink.logging.Logger;

/**
 * Interface that represents the execution context of the currently executing service flow
 */

public interface ProcessContext {
    /**
     * @return returns the service flow ID.
     */
    String getProcessId();

    /**
     * @return returns the instance ID of the service flow.
     */
    String getProcessInstanceId();

    /**
     * @return returns the system logger object.
     */
    Logger getUserLogger();

    /**
     * @return returns the variable information of the specified name in the scope of this service flow.
     */
    VariableContext getVariable(String variableName);

    /**
     * Returns the AnyLink execution environment variable value.
     * server.name, cluster.name, bizsystem.id are the currently supported environment variable keys.
     *
     * @param, key environment variable key
     * @return, environment variable value that corresponds to the key
     */
    String getenv(String key);
}

2.8. ProcessHandler

AnyLink process handler interface.

package com.tmax.anylink.api.serviceflow;

import com.tmax.anylink.common.AnyLinkException;

/**
 * AnyLink process handler interface.
 * When an object implementing this interface is registered as a handler of the corresponding service flow,
 * the corresponding methods are called according to the lifecycle of the service flow.
 */

public interface ProcessHandler {
    /**
     * Method called when the service flow is started.
     */
    void started(ProcessContext ctx) throws AnyLinkException;

    /**
     * Method called when the service flow is finished.
     */
    void finished(ProcessContext ctx) throws AnyLinkException;

    /**
     * Method called when the service flow is paused. Currently, this method is not used.
     */
    void paused(ProcessContext ctx) throws AnyLinkException;

    /**
     * Method called when the paused service flow is resumed. Currently, this method is not used.
     */
    void resumed(ProcessContext ctx) throws AnyLinkException;
}

2.9. ServiceActivityHandler

AnyLink service activity handler interface.

package com.tmax.anylink.api.serviceflow;

import com.tmax.anylink.api.MessageContext;
import com.tmax.anylink.common.AnyLinkException;

/**
 * AnyLink service activity handler interface.
 * This interface defines additional methods for each point in time in the service call.
 */

public interface ServiceActivityHandler extends ActivityHandler {
    /**
     * Method called just before calling the service.
     */
    void beforeServiceCall(ActivityContext ctx, MessageContext context) throws AnyLinkException;

    /**
     * Method called immediately after calling the service.
     */
    void afterServiceCall(ActivityContext ctx, MessageContext context) throws AnyLinkException;
}

2.10. UserActivity

Represents the user activity.

package com.tmax.anylink.api.serviceflow;

import com.tmax.anylink.common.AnyLinkException;

/**
 * Interface that represents the user activity.
 * To create a user class activity, users need to create a class that inherits the DefaultUserActivity abstract class that implements this interface.
 */

public interface UserActivity {
    /**
     * Main method that the user activity class should implement.
     */
    void action(ActivityContext ctx) throws AnyLinkException;
}

2.11. VariableContext

Defines the interface that corresponds to the service flow variable.

package com.tmax.anylink.api.serviceflow;

import com.tmax.anylink.api.MessageContext;

/**
 * Defines the interface that corresponds to the service flow variable.
 */

public interface VariableContext extends MessageContext {
    /**
     * Specify the variable data.
     *
     * @param content, data to be specified in the variable
     */
    void setContent(Object content);
}

Handler interfaces used by multi-binding routers are defined.

RoutingHandler
package com.tmax.anylink.api.multibinding;

import com.tmax.anylink.api.MessageContext;
import com.tmax.anylink.common.AnyLinkException;

/**
 * Multi-binding router's handler interface.
 * This handler class can be used when the multi-binding rule's routing method is specified as "Handler".
 */

public interface RoutingHandler {
    /**
     * @return returns the routing entry name.
     * To process the entry, the entry name must match at least one of entry values in the router rule.
     */
    String route(MessageContext ctx) throws AnyLinkException;
}

4. Default Abstract Class List

List of abstract classes that implement each of the interfaces mentioned above.

  • com.tmax.anylink.api.serviceflow.DefaultUserActivity

  • com.tmax.anylink.api.serviceflow.DefaultActivityHandler

  • com.tmax.anylink.api.serviceflow.DefaultProcessHandler

  • com.tmax.anylink.api.serviceflow.DefaultActivityErrorHandler

  • com.tmax.anylink.api.serviceflow.DefaultProcessErrorHandler

  • com.tmax.anylink.api.serviceflow.DefaultErrorCodeMapper

  • com.tmax.anylink.api.multibinding.DefaultRoutingHandler

It is recommended to implement an interface by inheriting the default abstract class, for future extensibility.