1 /*******************************************************************************
\r
2 * Copyright (c) 2010 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.databoard.method;
14 import java.util.concurrent.TimeUnit;
\r
16 import org.simantics.databoard.Datatypes;
\r
19 * MethodInterface is an interface for invoking methods.<p>
21 * If MethodInterface is executed on TCP/IP socket, the current
\r
22 * Connection can be acquired with Connection#getCurrentConnection().
\r
23 * You can attach close listener this way.<p>
\r
25 * MethodInterface may be used from multiple-threads simultaneously.
27 * @see Server puts a MethodInterface in a server socket
28 * @see Client creates a MethodInterface from a socket connection
29 * @see Datatypes to create MethodInterface from an interface
30 * @see Datatypes to create MethodInterface implementation from an object
31 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
32 * @author Hannu Niemisto
34 public interface MethodInterface {
37 * Get method descriptions
39 * @return method descriptions
41 Interface getInterface();
44 * Get an access to the implementation of a method. The binding is suggested by the producer.
46 * @param description method description
47 * @return method access
48 * @throws MethodNotSupportedException
50 Method getMethod(MethodTypeDefinition description)
51 throws MethodNotSupportedException;
54 * Get an access to the implementation of a method. The binding is suggested by the consumer.
56 * @param binding binding to use
57 * @return method access
58 * @throws MethodNotSupportedException
60 Method getMethod(MethodTypeBinding binding)
61 throws MethodNotSupportedException;
64 * Access to the implementation of a method.
66 public interface Method {
67 AsyncResult invoke(Object request);
68 MethodTypeBinding getMethodBinding();
71 public interface AsyncResult {
74 * Add a listener. It will be notified immediately if the response is
77 * @param listener (listener may not block) or null to remove listener
79 void setListener(InvokeListener listener);
83 * @return response or null
87 Object getExecutionError();
89 InvokeException getInvokeException();
91 AsyncRequestStatus getStatus();
96 * @throws InterruptedException block was canceled
97 * @throws InvokeException network error, e.g. IOException of MethodNotSupportedException
98 * @throws ExecutionError error that occured while executing the method
100 Object waitForResponse()
101 throws InvokeException, ExecutionError, InterruptedException;
106 * @throws InterruptedException
107 * @throws InvokeException network error, e.g. IOException of MethodNotSupportedException
108 * @throws ExecutionError error that occured while executing the method
110 Object waitForResponse(long timeout, TimeUnit unit)
111 throws InvokeException, ExecutionError, InterruptedException;
115 enum AsyncRequestStatus {Waiting, Succeed, Failed}
117 public interface InvokeListener {
118 void onCompleted(Object result);
119 void onExecutionError(Object error);
120 void onException(Exception cause);
124 * A wrapper to an error that occured in the execution of the method.
126 public static class ExecutionError extends Exception {
127 private static final long serialVersionUID = 1L;
129 public ExecutionError(Object error) {
132 public Object getError() {