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.accessor.wire;
\r
14 import java.util.LinkedList;
\r
16 import org.simantics.databoard.accessor.event.Event;
\r
17 import org.simantics.databoard.accessor.interestset.InterestSet;
\r
18 import org.simantics.databoard.accessor.reference.ChildReference;
\r
19 import org.simantics.databoard.annotations.Optional;
\r
20 import org.simantics.databoard.binding.mutable.MutableVariant;
\r
21 import org.simantics.databoard.type.Datatype;
\r
23 public interface IWireServer {
\r
26 * Open a handle to an accessor.
\r
28 * @param ref accessor refence or <code>null<code> for root
\r
29 * @return accessor info
\r
30 * @throws WireException
\r
32 AccessorInfo openAccessor(ChildReference ref) throws WireException;
\r
34 static class AccessorInfo {
\r
35 public int accessorId;
\r
36 public Datatype type;
\r
40 * Close a group of accessor handles.
\r
41 * Open listener and lock handles are released.
\r
43 * @param accIds accessor ids
\r
45 int closeAccessors(Integer[] accIds) throws WireException;
\r
48 * Acquire mutual-exclusive write lock, and optionally read lock.
\r
49 * The lock covers the node and its sub-tree.
\r
51 * Lock prevents access from other wire clients.
\r
55 * @param timeout in milliseconds, -1 = infinite
\r
56 * @return lockId, or -1 if failed
\r
58 // int requestLock(int accId, boolean readLock, long timeout) throws WireException;
\r
65 // void releaseLock(int lockId);
\r
68 * Read the value as whole.
\r
70 * If accessor is locked, read operation delays until lock
\r
75 * @throws WireException
\r
77 MutableVariant getValue(int accId) throws WireException;
\r
80 * Apply a list of changes to the node.
\r
82 * If rollback is true, a rollback log is returned.
\r
83 * Rollback log is a list of events that revert modifications
\r
86 * In case of error rollback log is filled with
\r
87 * events that counter modification that were already applied
\r
88 * before the error occured.<p>
\r
93 * @return apply result
\r
95 ApplyResult apply(int accId, Event[] changeSet, boolean rollback);
\r
97 public static class ApplyResult {
\r
98 public @Optional WireException error;
\r
99 public @Optional LinkedList<Event> rollbackLog;
\r
106 * @param interestSet
\r
107 * @param pathPrefix
\r
109 * @throws WireException
\r
111 int addListener(int accId, InterestSet interestSet, ChildReference pathPrefix) throws WireException;
\r
117 * @throws WireException
\r
119 int removeListener(int lisId) throws WireException;
\r
121 // Array, Map, Record, Union
\r
123 * Get size of an array, map, record or union
\r
126 * @throws WireException
\r
128 int size(int accId) throws WireException;
\r
131 * Remove all array or map elements
\r
134 * @throws WireException
\r
136 int clear(int accId) throws WireException;
\r
138 boolean containsKey(int accId, MutableVariant key) throws WireException;
\r
139 boolean containsValue(int accId, MutableVariant value) throws WireException;
\r
140 MutableVariant getFirstKey(int accId) throws WireException;
\r
141 MutableVariant getLastKey(int accId) throws WireException;
\r
142 MutableVariant getLowerKey(int accId, MutableVariant key) throws WireException;
\r
143 MutableVariant getFloorKey(int accId, MutableVariant key) throws WireException;
\r
144 MutableVariant getCeilingKey(int accId, MutableVariant key) throws WireException;
\r
145 MutableVariant getHigherKey(int accId, MutableVariant key) throws WireException;
\r
148 * Get map entry value
\r
153 * @throws WireException
\r
155 MutableVariant getMapValue(int accId, MutableVariant key) throws WireException;
\r
158 * Get map values as array
\r
161 * @return values in array inside a variant
\r
162 * @throws WireException
\r
164 MutableVariant getMapValues(int accId) throws WireException;
\r
167 * Get map keys as array
\r
170 * @return keys in array inside a variant
\r
171 * @throws WireException
\r
173 MutableVariant getMapKeys(int accId) throws WireException;
\r
177 * Get value status of an Optional node
\r
180 * @return <code>true</code> if there is value in the node
\r
181 * @throws WireException
\r
183 boolean hasValue(int accId) throws WireException;
\r
187 * Get tag index of a Union node
\r
190 * @return tag index
\r
191 * @throws WireException
\r
193 int getTag(int accId) throws WireException;
\r
198 * add objects to array
\r
201 * @param index insert pos, -1 = at the end
\r
203 * @return actual insert pos
\r
205 int addAll(int accId, int index, MutableVariant array) throws WireException;
\r
210 * @param index insert pos, -1 = at the end
\r
212 * @return actual insert pos
\r
213 * @throws WireException
\r
215 int add(int accId, int index, MutableVariant object) throws WireException;
\r
218 * Get array element value
\r
223 * @throws WireException
\r
225 MutableVariant getArrayElement(int accId, int index) throws WireException;
\r