- java.lang.Object
-
- org.cloudi.API
-
public class API extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAPI.FatalErrorstatic classAPI.ForwardAsyncExceptionstatic classAPI.ForwardSyncExceptionstatic classAPI.InvalidInputExceptionstatic classAPI.MessageDecodingExceptionstatic classAPI.Responsestatic classAPI.ReturnAsyncExceptionstatic classAPI.ReturnSyncExceptionstatic classAPI.TerminateExceptionstatic classAPI.TransId
-
Field Summary
Fields Modifier and Type Field Description static intASYNCstatic PrintStreamerrstatic PrintStreamoutstatic intSYNCstatic byte[]TransIdNull
-
Constructor Summary
Constructors Constructor Description API(int thread_index)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidforward_(Integer request_type, String name, byte[] request_info, byte[] request, Integer timeout, Byte priority, byte[] trans_id, OtpErlangPid source)Forward a message to another service subscribed that matches the destination servicename.voidforward_async(String name, byte[] request_info, byte[] request, Integer timeout, Byte priority, byte[] trans_id, OtpErlangPid source)Asynchronously forward a message to another service subscribed that matches the destination servicename.voidforward_sync(String name, byte[] request_info, byte[] request, Integer timeout, Byte priority, byte[] trans_id, OtpErlangPid source)Synchronously forward a message to another service subscribed that matches the destination servicename.static byte[]info_key_value_new(HashMap<String,ArrayList<String>> pairs)Encode service response info key/value datastatic byte[]info_key_value_new(HashMap<String,ArrayList<String>> pairs, boolean response)Encode service response info key/value datastatic byte[]info_key_value_new(Map<String,List<String>> pairs)Encode service response info key/value datastatic byte[]info_key_value_new(Map<String,List<String>> pairs, boolean response)Encode service response info key/value datastatic HashMap<String,ArrayList<String>>info_key_value_parse(byte[] info)Decode service request info key/value dataArrayList<API.TransId>mcast_async(String name, byte[] request)Asynchronous point-multicast communication to services subscribed that matches the destination servicename.ArrayList<API.TransId>mcast_async(String name, byte[] request_info, byte[] request, Integer timeout, Byte priority)Asynchronous point-multicast communication to services subscribed that matches the destination servicename.booleanpoll()Blocks to process incoming CloudI service requestsbooleanpoll(int timeout)Blocks to process incoming CloudI service requestsStringprefix()bytepriority_default()intprocess_count()intprocess_count_max()intprocess_count_min()intprocess_index()API.Responserecv_async()Asynchronously receive a response.API.Responserecv_async(boolean consume)Asynchronously receive a response.API.Responserecv_async(byte[] trans_id)Asynchronously receive a response.API.Responserecv_async(byte[] trans_id, boolean consume)Asynchronously receive a response.API.Responserecv_async(Integer timeout)Asynchronously receive a response.API.Responserecv_async(Integer timeout, boolean consume)Asynchronously receive a response.API.Responserecv_async(Integer timeout, byte[] trans_id)Asynchronously receive a response.API.Responserecv_async(Integer timeout, byte[] trans_id, boolean consume)Asynchronously receive a response.voidreturn_(Integer request_type, String name, String pattern, byte[] response_info, byte[] response, Integer timeout, byte[] trans_id, OtpErlangPid source)Returns a response from a service request.voidreturn_async(String name, String pattern, byte[] response_info, byte[] response, Integer timeout, byte[] trans_id, OtpErlangPid source)Asynchronously returns a response from a service request.voidreturn_sync(String name, String pattern, byte[] response_info, byte[] response, Integer timeout, byte[] trans_id, OtpErlangPid source)Synchronously returns a response from a service request.API.TransIdsend_async(String name, byte[] request)Asynchronous point-to-point communication to a service subscribed that matches the destination servicename.API.TransIdsend_async(String name, byte[] request_info, byte[] request, Integer timeout, Byte priority)Asynchronous point-to-point communication to a service subscribed that matches the destination servicename.API.Responsesend_sync(String name, byte[] request)Synchronous point-to-point communication to a service subscribed that matches the destination servicename.API.Responsesend_sync(String name, byte[] request_info, byte[] request, Integer timeout, Byte priority)Synchronous point-to-point communication to a service subscribed that matches the destination servicename.voidshutdown()Shutdown the service successfullyvoidshutdown(String reason)Shutdown the service successfullyvoidsubscribe(String pattern, Class<?> clazz, String methodName)Subscribes a static method to a service name pattern.voidsubscribe(String pattern, Object instance, String methodName)Subscribes an object method to a service name pattern.voidsubscribe(String pattern, FunctionInterface10 callback)Subscribes a static method to a service name pattern.voidsubscribe(String pattern, FunctionInterface9 callback)Subscribes an object method to a service name pattern.intsubscribe_count(String pattern)Determine how may service name pattern subscriptions have occurred.static intthread_count()inttimeout_async()inttimeout_initialize()inttimeout_sync()inttimeout_terminate()voidunsubscribe(String pattern)Unsubscribes from a service name pattern.
-
-
-
Field Detail
-
out
public static final PrintStream out
-
err
public static final PrintStream err
-
ASYNC
public static final int ASYNC
- See Also:
- Constant Field Values
-
SYNC
public static final int SYNC
- See Also:
- Constant Field Values
-
TransIdNull
public static final byte[] TransIdNull
-
-
Constructor Detail
-
API
public API(int thread_index) throws API.InvalidInputException, API.MessageDecodingException, API.TerminateException
-
-
Method Detail
-
thread_count
public static int thread_count() throws API.InvalidInputException- Returns:
- the number of threads to create per operating system process
- Throws:
API.InvalidInputException- service execution failure
-
subscribe
public void subscribe(String pattern, Object instance, String methodName) throws NoSuchMethodException
Subscribes an object method to a service name pattern.- Parameters:
pattern- the service name patterninstance- the object instancemethodName- the object method to handle matching requests- Throws:
NoSuchMethodException- instance method arity is invalid
-
subscribe
public void subscribe(String pattern, Class<?> clazz, String methodName) throws NoSuchMethodException
Subscribes a static method to a service name pattern.- Parameters:
pattern- the service name patternclazz- the class of the static methodmethodName- the static method to handle matching requests- Throws:
NoSuchMethodException- instance method arity is invalid
-
subscribe
public void subscribe(String pattern, FunctionInterface10 callback)
Subscribes a static method to a service name pattern.- Parameters:
pattern- the service name patterncallback- method reference for callback (Java 8 or higher)
-
subscribe
public void subscribe(String pattern, FunctionInterface9 callback)
Subscribes an object method to a service name pattern.- Parameters:
pattern- the service name patterncallback- method reference for callback (Java 8 or higher)
-
subscribe_count
public int subscribe_count(String pattern) throws API.InvalidInputException, API.TerminateException
Determine how may service name pattern subscriptions have occurred.- Parameters:
pattern- the service name pattern- Returns:
- count of active subscriptions
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.TerminateException- service execution must terminate
-
unsubscribe
public void unsubscribe(String pattern) throws API.InvalidInputException
Unsubscribes from a service name pattern.- Parameters:
pattern- the service name pattern- Throws:
API.InvalidInputException- not subscribed to service name pattern
-
send_async
public API.TransId send_async(String name, byte[] request) throws API.InvalidInputException, API.MessageDecodingException, API.TerminateException
Asynchronous point-to-point communication to a service subscribed that matches the destination servicename.- Parameters:
name- the destination service namerequest- the request data- Returns:
- a transaction ID
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.MessageDecodingException- service messaging failureAPI.TerminateException- service execution must terminate
-
send_async
public API.TransId send_async(String name, byte[] request_info, byte[] request, Integer timeout, Byte priority) throws API.InvalidInputException, API.MessageDecodingException, API.TerminateException
Asynchronous point-to-point communication to a service subscribed that matches the destination servicename.- Parameters:
name- the destination service namerequest_info- any request metadatarequest- the request datatimeout- the request timeout in millisecondspriority- the request priority- Returns:
- a transaction ID
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.MessageDecodingException- service messaging failureAPI.TerminateException- service execution must terminate
-
send_sync
public API.Response send_sync(String name, byte[] request) throws API.InvalidInputException, API.MessageDecodingException, API.TerminateException
Synchronous point-to-point communication to a service subscribed that matches the destination servicename.- Parameters:
name- the destination service namerequest- the request data- Returns:
- the response
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.MessageDecodingException- service messaging failureAPI.TerminateException- service execution must terminate
-
send_sync
public API.Response send_sync(String name, byte[] request_info, byte[] request, Integer timeout, Byte priority) throws API.InvalidInputException, API.MessageDecodingException, API.TerminateException
Synchronous point-to-point communication to a service subscribed that matches the destination servicename.- Parameters:
name- the destination service namerequest_info- any request metadatarequest- the request datatimeout- the request timeout in millisecondspriority- the request priority- Returns:
- the response
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.MessageDecodingException- service messaging failureAPI.TerminateException- service execution must terminate
-
mcast_async
public ArrayList<API.TransId> mcast_async(String name, byte[] request) throws API.InvalidInputException, API.MessageDecodingException, API.TerminateException
Asynchronous point-multicast communication to services subscribed that matches the destination servicename.- Parameters:
name- the destination service namerequest- the request data- Returns:
- transaction IDs
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.MessageDecodingException- service messaging failureAPI.TerminateException- service execution must terminate
-
mcast_async
public ArrayList<API.TransId> mcast_async(String name, byte[] request_info, byte[] request, Integer timeout, Byte priority) throws API.InvalidInputException, API.MessageDecodingException, API.TerminateException
Asynchronous point-multicast communication to services subscribed that matches the destination servicename.- Parameters:
name- the destination service namerequest_info- any request metadatarequest- the request datatimeout- the request timeout in millisecondspriority- the priority of this request- Returns:
- transaction IDs
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.MessageDecodingException- service messaging failureAPI.TerminateException- service execution must terminate
-
forward_
public void forward_(Integer request_type, String name, byte[] request_info, byte[] request, Integer timeout, Byte priority, byte[] trans_id, OtpErlangPid source) throws API.ForwardAsyncException, API.ForwardSyncException, API.InvalidInputException
Forward a message to another service subscribed that matches the destination servicename.- Parameters:
request_type- constant API.SYNC or API.ASYNCname- the destination service namerequest_info- any request metadatarequest- the request datatimeout- the request timeout in millisecondspriority- the priority of this requesttrans_id- the transaction IDsource- the request's source process ID- Throws:
API.ForwardAsyncException- async service request was forwardedAPI.ForwardSyncException- sync service request was forwardedAPI.InvalidInputException- invalid service request type
-
forward_async
public void forward_async(String name, byte[] request_info, byte[] request, Integer timeout, Byte priority, byte[] trans_id, OtpErlangPid source) throws API.ForwardAsyncException
Asynchronously forward a message to another service subscribed that matches the destination servicename.- Parameters:
name- the destination service namerequest_info- any request metadatarequest- the request datatimeout- the request timeout in millisecondspriority- the priority of this requesttrans_id- the transaction IDsource- the request's source process ID- Throws:
API.ForwardAsyncException- async service request was forwarded
-
forward_sync
public void forward_sync(String name, byte[] request_info, byte[] request, Integer timeout, Byte priority, byte[] trans_id, OtpErlangPid source) throws API.ForwardSyncException
Synchronously forward a message to another service subscribed that matches the destination servicename.- Parameters:
name- the destination service namerequest_info- any request metadatarequest- the request datatimeout- the request timeout in millisecondspriority- the priority of this requesttrans_id- the transaction IDsource- the request's source process ID- Throws:
API.ForwardSyncException- sync service request was forwarded
-
return_
public void return_(Integer request_type, String name, String pattern, byte[] response_info, byte[] response, Integer timeout, byte[] trans_id, OtpErlangPid source) throws API.ReturnAsyncException, API.ReturnSyncException, API.InvalidInputException
Returns a response from a service request.- Parameters:
request_type- constant API.SYNC or API.SYNCname- the service namepattern- the service name patternresponse_info- any response metadataresponse- the response datatimeout- the request timeout in millisecondstrans_id- the transaction IDsource- the request's source process ID- Throws:
API.ReturnAsyncException- async service request returnedAPI.ReturnSyncException- sync service request returnedAPI.InvalidInputException- invalid service request type
-
return_async
public void return_async(String name, String pattern, byte[] response_info, byte[] response, Integer timeout, byte[] trans_id, OtpErlangPid source) throws API.ReturnAsyncException
Asynchronously returns a response from a service request.- Parameters:
name- the service namepattern- the service name patternresponse_info- any response metadataresponse- the response datatimeout- the request timeout in millisecondstrans_id- the transaction IDsource- the request's source process ID- Throws:
API.ReturnAsyncException- async service request returned
-
return_sync
public void return_sync(String name, String pattern, byte[] response_info, byte[] response, Integer timeout, byte[] trans_id, OtpErlangPid source) throws API.ReturnSyncException
Synchronously returns a response from a service request.- Parameters:
name- the service namepattern- the service name patternresponse_info- any response metadataresponse- the response datatimeout- the request timeout in millisecondstrans_id- the transaction IDsource- the request's source process ID- Throws:
API.ReturnSyncException- sync service request returned
-
recv_async
public API.Response recv_async() throws API.InvalidInputException, API.MessageDecodingException, API.TerminateException
Asynchronously receive a response.- Returns:
- the response
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.MessageDecodingException- service messaging failureAPI.TerminateException- service execution must terminate
-
recv_async
public API.Response recv_async(Integer timeout) throws API.InvalidInputException, API.MessageDecodingException, API.TerminateException
Asynchronously receive a response.- Parameters:
timeout- the receive timeout in milliseconds- Returns:
- the response
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.MessageDecodingException- service messaging failureAPI.TerminateException- service execution must terminate
-
recv_async
public API.Response recv_async(byte[] trans_id) throws API.InvalidInputException, API.MessageDecodingException, API.TerminateException
Asynchronously receive a response.- Parameters:
trans_id- the transaction ID to receive- Returns:
- the response
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.MessageDecodingException- service messaging failureAPI.TerminateException- service execution must terminate
-
recv_async
public API.Response recv_async(boolean consume) throws API.InvalidInputException, API.MessageDecodingException, API.TerminateException
Asynchronously receive a response.- Parameters:
consume- iftrue, will consume the service request so it is not accessible with the same function call in the future- Returns:
- the response
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.MessageDecodingException- service messaging failureAPI.TerminateException- service execution must terminate
-
recv_async
public API.Response recv_async(Integer timeout, byte[] trans_id) throws API.InvalidInputException, API.MessageDecodingException, API.TerminateException
Asynchronously receive a response.- Parameters:
timeout- the receive timeout in millisecondstrans_id- the transaction ID to receive- Returns:
- the response
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.MessageDecodingException- service messaging failureAPI.TerminateException- service execution must terminate
-
recv_async
public API.Response recv_async(Integer timeout, boolean consume) throws API.InvalidInputException, API.MessageDecodingException, API.TerminateException
Asynchronously receive a response.- Parameters:
timeout- the receive timeout in millisecondsconsume- iftrue, will consume the service request so it is not accessible with the same function call in the future- Returns:
- the response
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.MessageDecodingException- service messaging failureAPI.TerminateException- service execution must terminate
-
recv_async
public API.Response recv_async(byte[] trans_id, boolean consume) throws API.InvalidInputException, API.MessageDecodingException, API.TerminateException
Asynchronously receive a response.- Parameters:
trans_id- the transaction ID to receiveconsume- iftrue, will consume the service request so it is not accessible with the same function call in the future- Returns:
- the response
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.MessageDecodingException- service messaging failureAPI.TerminateException- service execution must terminate
-
recv_async
public API.Response recv_async(Integer timeout, byte[] trans_id, boolean consume) throws API.InvalidInputException, API.MessageDecodingException, API.TerminateException
Asynchronously receive a response.- Parameters:
timeout- the receive timeout in millisecondstrans_id- the transaction ID to receiveconsume- iftrue, will consume the service request so it is not accessible with the same function call in the future- Returns:
- the response
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.MessageDecodingException- service messaging failureAPI.TerminateException- service execution must terminate
-
process_index
public int process_index()
-
process_count
public int process_count()
-
process_count_max
public int process_count_max()
-
process_count_min
public int process_count_min()
-
prefix
public String prefix()
-
timeout_initialize
public int timeout_initialize()
-
timeout_async
public int timeout_async()
-
timeout_sync
public int timeout_sync()
-
timeout_terminate
public int timeout_terminate()
-
priority_default
public byte priority_default()
-
poll
public boolean poll() throws API.InvalidInputException, API.MessageDecodingException, API.TerminateExceptionBlocks to process incoming CloudI service requests- Returns:
- false
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.MessageDecodingException- service messaging failureAPI.TerminateException- service execution must terminate
-
poll
public boolean poll(int timeout) throws API.InvalidInputException, API.MessageDecodingException, API.TerminateExceptionBlocks to process incoming CloudI service requests- Parameters:
timeout- the block timeout in milliseconds (-1 is infinity)- Returns:
- a boolean to determine if a timeout occurred
- Throws:
API.InvalidInputException- invalid input to internal function callAPI.MessageDecodingException- service messaging failureAPI.TerminateException- service execution must terminate
-
shutdown
public void shutdown()
Shutdown the service successfully
-
shutdown
public void shutdown(String reason)
Shutdown the service successfully- Parameters:
reason- the shutdown reason
-
info_key_value_parse
public static HashMap<String,ArrayList<String>> info_key_value_parse(byte[] info)
Decode service request info key/value data- Parameters:
info- encoded binary- Returns:
- info key/value map
-
info_key_value_new
public static byte[] info_key_value_new(Map<String,List<String>> pairs)
Encode service response info key/value data- Parameters:
pairs- info key/value map- Returns:
- encoded binary
-
info_key_value_new
public static byte[] info_key_value_new(HashMap<String,ArrayList<String>> pairs)
Encode service response info key/value data- Parameters:
pairs- info key/value map- Returns:
- encoded binary
-
info_key_value_new
public static byte[] info_key_value_new(Map<String,List<String>> pairs, boolean response)
Encode service response info key/value data- Parameters:
pairs- info key/value mapresponse- if encoding response data- Returns:
- encoded binary
-
-