| 1 | /** |
| 2 | * Copyright (C) 2006 NetMind Consulting Bt. |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 3 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | */ |
| 18 | |
| 19 | package hu.netmind.beankeeper.node; |
| 20 | |
| 21 | import hu.netmind.beankeeper.service.Service; |
| 22 | import java.util.List; |
| 23 | |
| 24 | /** |
| 25 | * This is the interface which provides communication services |
| 26 | * to other nodes. |
| 27 | * @author Brautigam Robert |
| 28 | * @version Revision: $Revision$ |
| 29 | */ |
| 30 | public interface NodeManager extends Service |
| 31 | { |
| 32 | public enum NodeRole |
| 33 | { |
| 34 | CLIENT, // Node is a client node in the network |
| 35 | SERVER; // Node is server node |
| 36 | }; |
| 37 | |
| 38 | public enum NodeState |
| 39 | { |
| 40 | OFFLINE(0), // Manager created, but no identity yet |
| 41 | UNINITIALIZED(1), // No identity, but it was tried |
| 42 | INITIALIZED(2), // Node has identity, but is not connected |
| 43 | CONNECTED(4); // Connected and ready to communicate |
| 44 | |
| 45 | private int level; |
| 46 | |
| 47 | private NodeState(int level) |
| 48 | { |
| 49 | this.level=level; |
| 50 | } |
| 51 | |
| 52 | public int getLevel() |
| 53 | { |
| 54 | return level; |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | /** |
| 59 | * Get the node's unique id between nodes. This id may change during a |
| 60 | * reconnect, but it is guaranteed to be unique among nodes at any given time. |
| 61 | */ |
| 62 | Integer getId(); |
| 63 | |
| 64 | /** |
| 65 | * Get the server node's unique id. If this is a client node, it contains |
| 66 | * the server node's id this is connected to, otherwise it's the same as |
| 67 | * <code>getId()</code>. |
| 68 | */ |
| 69 | Integer getServerId(); |
| 70 | |
| 71 | /** |
| 72 | * Get the node's role in the network. |
| 73 | */ |
| 74 | NodeRole getRole(); |
| 75 | |
| 76 | /** |
| 77 | * Get the state of the node. |
| 78 | */ |
| 79 | NodeState getState(); |
| 80 | |
| 81 | /** |
| 82 | * Make a potentially remote call to the given service, with given |
| 83 | * parameters. This call will always go to the server |
| 84 | * node for execution. If this is the server node, then |
| 85 | * the service will be called locally. |
| 86 | * @return The object that was returned from RPC. |
| 87 | */ |
| 88 | Object callServer(String service, String method, Class[] parameterTypes, |
| 89 | Object[] parameters); |
| 90 | |
| 91 | /** |
| 92 | * Call this method on all nodes, including where the call originated. |
| 93 | * Note, broadcast calls do not have return value. It is guaranteed however, |
| 94 | * that any given node either received the call, or fell off the node |
| 95 | * network before this call returns. It is not guaranteed however, |
| 96 | * that all calls were successful in their respective nodes. |
| 97 | */ |
| 98 | void callAll(String service, String method, Class[] parameterTypes, |
| 99 | Object[] parameters); |
| 100 | |
| 101 | } |
| 102 | |
| 103 | |