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