1 package at.ac.tuwien.sbc.valesriegler.xvsm;
3 import java.util.ArrayList;
4 import java.util.Arrays;
7 import org.mozartspaces.capi3.AnyCoordinator;
8 import org.mozartspaces.capi3.Coordinator;
9 import org.mozartspaces.core.Capi;
10 import org.mozartspaces.core.ContainerReference;
11 import org.mozartspaces.core.DefaultMzsCore;
12 import org.mozartspaces.core.Entry;
13 import org.mozartspaces.core.MzsCore;
14 import org.mozartspaces.core.MzsCoreException;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 import at.ac.tuwien.sbc.valesriegler.common.SpaceUtil;
19 import at.ac.tuwien.sbc.valesriegler.types.Table;
22 * Responsible for XVSM Communication
24 * @author Gregor Riegler <gregor DOT riegler AT gmail DOT com>
27 public class XVSMConnector {
28 private static final Logger log = LoggerFactory.getLogger(XVSMConnector.class);
30 private ContainerReference tablesContainer;
33 public void initSpaceCommunication() throws MzsCoreException {
34 MzsCore core = DefaultMzsCore.newInstanceWithoutSpace();
35 capi = new Capi(core);
36 tablesContainer = SpaceUtil.getOrCreateNamedContainer(SpaceUtil.SERVER_ADDR, SpaceUtil.TABLES_CONTAINER, capi,
37 Arrays.asList((Coordinator) new AnyCoordinator()));
40 public void sendFreeTablesToSpace(List<Table> tables) {
42 List<Entry> entries = new ArrayList<>();
43 for (Table table : tables) {
44 entries.add(new Entry(table));
46 capi.write(entries, tablesContainer);
48 log.info("Wrote Free tables to Space!");
49 } catch (MzsCoreException e) {
54 public List<Table> readTables() {
55 ArrayList<Table> tables = new ArrayList<>();
57 tables = capi.take(tablesContainer);
58 } catch (MzsCoreException e) {
59 log.error(e.getMessage());