1 package org.simantics.databoard.example.old;
2 import java.io.IOException;
3 import java.util.Arrays;
5 import org.simantics.databoard.Methods;
6 import org.simantics.databoard.binding.error.BindingConstructionException;
7 import org.simantics.databoard.method.MethodInterface;
9 /*******************************************************************************
10 * Copyright (c) 2010 Association for Decentralized Information Management in
12 * All rights reserved. This program and the accompanying materials
13 * are made available under the terms of the Eclipse Public License v1.0
14 * which accompanies this distribution, and is available at
15 * http://www.eclipse.org/legal/epl-v10.html
18 * VTT Technical Research Centre of Finland - initial API and implementation
19 *******************************************************************************/
21 public class RPCExample2 {
23 public static class Server {
26 public interface NetworkProtocol {
28 String execute(String command, int[] args) throws Error1;
31 public static class Error1 extends Exception {
33 private static final long serialVersionUID = 1L;
35 public String errorMessage;
36 public Error1(String msg) {
37 this.errorMessage = msg;
40 public String toString() {
48 public static class Client {
49 public interface NetworkProtocol {
50 String execute(String cmd, int[] args) throws Error1;
53 public static class Error1 extends Exception {
55 private static final long serialVersionUID = 1L;
57 public String errorMessage;
58 public Error1(String errorMessage) {
59 this.errorMessage = errorMessage;
62 public String toString() {
63 return "Error occured: "+errorMessage;
70 public static void main(String[] args) throws IOException, BindingConstructionException {
73 Server.NetworkProtocol myServer = new Server.NetworkProtocol() {
75 public String execute(String command, int[] args) throws Server.Error1 {
76 if (!command.equals("start")) throw new Server.Error1("Unknown command "+command);
77 return "Program started "+command+" with args "+Arrays.toString(args);
81 public void elProblem() {
82 // TODO Auto-generated method stub
83 System.out.println("Works");
88 // Adapt server to MethodInterface
89 MethodInterface myMI = Methods.bindInterface(Server.NetworkProtocol.class, myServer);
93 // Adapt methodInterface to client
94 Client.NetworkProtocol myMiProxy = Methods.createProxy(Client.NetworkProtocol.class, myMI);
96 // Execute command "start"
98 String result = myMiProxy.execute("start", new int[] {5,6,72,7423});
99 System.out.println(result);
100 } catch (Client.Error1 e) {
101 System.err.println(e);
104 // Execute command "fault"
106 String result = myMiProxy.execute("fault", new int[] {});
107 System.out.println(result);
108 } catch (Client.Error1 e) {
109 System.err.println(e);