public void initialize() throws Exception { // Load the local context counter Long contextCounterL = (Long)transaction.load( CTX_COUNTER); if (contextCounterL == null) { contextCounter = 0; } else { contextCounter = contextCounterL.longValue(); } // Load the context index nameToIdIndex = (Hashtable)transaction.load(CTX_INDEX); if (nameToIdIndex == null) { nameToIdIndex = new Hashtable(); } }
/** * Saves object in persistent storage. */ static void save() throws IOException { AgentServer.getTransaction().save(manager, "serviceManager"); // with OSGi the service start asynchronously, // and perhaps without running transaction. AgentServer.getTransaction().begin(); AgentServer.getTransaction().commit(true); if (xlogmon.isLoggable(BasicLevel.DEBUG)) xlogmon.log(BasicLevel.DEBUG, getName() + " service manager saved."); }
/** * Deletes the current object in persistent storage. */ void delete() { if (isPersistent) { AgentServer.getTransaction().delete(name); } }
/** Deletes all persisted objects. */ public static void deleteAll(String msgTxname) { if (logger.isLoggable(BasicLevel.DEBUG)) logger.log(BasicLevel.DEBUG, "MessagePersistenceModule.deleteAll() " + msgTxname); Transaction tx = AgentServer.getTransaction(); // Retrieving the names of the persistence message previously saved. String[] names = tx.getList(msgTxname); // Deleting the message. for (int i = 0; i < names.length; i++) { tx.delete(names[i]); tx.delete(names[i] + "B"); } }
/** * Reset all information related to server sid in the network configuration. * * @param id the unique server id. */ synchronized void resetServer(short id, int boot) throws IOException { // First we have to verify that id is already in servers int idx = index(id); if (idx < 0) return; // TODO... // Save the servers configuration and the logical time stamp. AgentServer.getTransaction().save(servers, serversFN); AgentServer.getTransaction().save(bootTS, bootTSFN); AgentServer.getTransaction().saveByteArray(stampbuf, name); }
idxLS = index(sid); stampbuf = AgentServer.getTransaction().loadByteArray(name); if (stampbuf == null) { AgentServer.getTransaction().save(servers, serversFN); AgentServer.getTransaction().save(bootTS, bootTSFN); AgentServer.getTransaction().saveByteArray(stampbuf, name); } else { short[] s = (short[]) AgentServer.getTransaction().load(serversFN); bootTS = (int[]) AgentServer.getTransaction().load(bootTSFN); stamp = new int[s.length]; for (int i=0; i<stamp.length; i++) {
/** * Saves the object state on persistent storage. */ void save() throws IOException { AgentServer.getTransaction().save(this, "AgentIdStamp"); }
void receiveFromJGroups(Message msg) throws Exception { if (logmon.isLoggable(BasicLevel.DEBUG)) logmon.log(BasicLevel.DEBUG, getName() + " receiveFromJGroups(" + msg + ")"); AgentServer.getTransaction().begin(); stamp(msg); msg.save(); if (logmon.isLoggable(BasicLevel.DEBUG)) logmon.log(BasicLevel.DEBUG,getName() + " receiveFromJGroups qin.size() = " + qin.size() + ", qinFromExt.size() = " + qinFromExt.size()); AgentServer.getTransaction().commit(false); qinFromExt.addElement(msg); postFromExt(); AgentServer.getTransaction().release(); }
transaction.init(path); } catch (IOException exc) { logmon.log(BasicLevel.FATAL, getName() + ", can't start transaction manager", exc); transaction.init(path); } catch (IOException exc) { logmon.log(BasicLevel.FATAL, getName() + ", can't start transaction manager", exc); String[] list = transaction.getList("@"); for (int i=0; i<list.length; i++) { Message msg = Message.load(list[i]); transaction.begin(); transaction.commit(true);
/** Loads all persisted messages. */ public static Vector loadAll(String msgTxname) { if (logger.isLoggable(BasicLevel.DEBUG)) logger.log(BasicLevel.DEBUG, "MessagePersistenceModule.loadAll() " + msgTxname); Vector messages = new Vector(); // Retrieving the names of the persistence message previously saved. Transaction tx = AgentServer.getTransaction(); String[] names = tx.getList(msgTxname); // Retrieving the messages individually persisted. for (int i = 0; i < names.length; i++) { if (names[i].charAt(names[i].length() - 1) != 'B') { try { Message msg = (Message) tx.load(names[i]); msg.txname = names[i]; if (logger.isLoggable(BasicLevel.DEBUG)) logger.log(BasicLevel.DEBUG, "loadAll: names[" + i + "] = " + msg); messages.add(msg); } catch (Exception exc) { logger.log(BasicLevel.ERROR, "Message named [" + names[i] + "] could not be loaded", exc); } } } return messages; }
public void save() { if (logger.isLoggable(BasicLevel.DEBUG)) logger.log(BasicLevel.DEBUG, "Message.save:" + txname); if (!isPersistent()) return; if (soft) { byte[] body = msg.body; // sets the body to null to save it in an other file msg.body = null; try { AgentServer.getTransaction().create(this, txname); } catch (IOException exc) { logger.log(BasicLevel.ERROR, "Message named [" + txname + "] could not be saved", exc); } // save the body try { // The body is RO do not copy it. AgentServer.getTransaction().saveByteArray(body, null, txname + "B", false, true); } catch (IOException exc) { logger.log(BasicLevel.ERROR, "Message named [" + txname + "] could not be saved", exc); } msg.body = body; } else { try { AgentServer.getTransaction().create(this, txname); } catch (IOException exc) { logger.log(BasicLevel.ERROR, "Message named [" + txname + "] could not be saved", exc); } } }
private void updateStamp(int idx, int update) throws IOException { stamp[idx] = update; stampbuf[(idx*4)+0] = (byte)((update >>> 24) & 0xFF); stampbuf[(idx*4)+1] = (byte)((update >>> 16) & 0xFF); stampbuf[(idx*4)+2] = (byte)((update >>> 8) & 0xFF); stampbuf[(idx*4)+3] = (byte)(update & 0xFF); AgentServer.getTransaction().saveByteArray(stampbuf, name); }
/** * Restores logical clock information from persistent storage. */ public void restore() throws Exception { stampBuf = AgentServer.getTransaction().loadByteArray(getName()); if (stampBuf == null) { stamp = 0; stampBuf = new byte[4]; modified = true; } else { stamp = ((stampBuf[0] & 0xFF) << 24) + ((stampBuf[1] & 0xFF) << 16) + ((stampBuf[2] & 0xFF) << 8) + (stampBuf[3] & 0xFF); modified = false; } }
/** * Saves the object state on persistent storage. */ void save() throws IOException { if (isPersistent()) { AgentServer.getTransaction().create(this, toStringId()); if (not.detachable) { not.messageId = StringId.toStringId('N', '_', dest, stamp, -1); AgentServer.getTransaction().create(not, not.messageId); } } }
idxLS = index(sid); stampbuf = AgentServer.getTransaction().loadByteArray(name); if (stampbuf == null) { AgentServer.getTransaction().save(servers, serversFN); AgentServer.getTransaction().save(bootTS, bootTSFN); AgentServer.getTransaction().saveByteArray(stampbuf, name); } else { short[] s = (short[]) AgentServer.getTransaction().load(serversFN); bootTS = (int[]) AgentServer.getTransaction().load(bootTSFN); stamp = new int[s.length]; for (int i=0; i<stamp.length; i++) {
private void saveServers() { try { AgentServer.getTransaction().save(servers, SERVER_LIST); } catch (IOException exc) { throw new Error(exc.toString()); } }
/** * Reset all information related to server sid in the network configuration. * * @param id the unique server id. */ synchronized void resetServer(short id, int boot) throws IOException { // First we have to verify that id is already in servers int idx = index(id); if (idx < 0) return; // TODO... // Save the servers configuration and the logical time stamp. AgentServer.getTransaction().save(servers, serversFN); AgentServer.getTransaction().save(bootTS, bootTSFN); AgentServer.getTransaction().saveByteArray(stampbuf, name); }