public ReturnTuple<Integer> newCustomer(int id, Timestamp timestamp) throws RemoteException, TransactionAbortedException, InvalidTransactionException { if (!isMaster) { System.out.println("Slave retransmitting newCustomer to master"); return this.getMaster().newCustomer(id, timestamp); } else { timestamp.stamp(); int rid = Integer.parseInt( String.valueOf(id) + String.valueOf(Calendar.getInstance().get(Calendar.MILLISECOND)) + String.valueOf(Math.round(Math.random() * 100 + 1))); NewCustomerWithIdRMICommand nc = new NewCustomerWithIdRMICommand(carGroup, flightGroup, roomGroup, id, rid); nc.setTimestampObject(timestamp); ReturnTuple<Integer> result = null; try { overseer.validTransaction(id); lm.Lock(id, Customer.getKey(rid), nc.getRequiredLock()); nc.execute(); result = new ReturnTuple<Integer>(rid, nc.success.timestamp); overseer.addCommandToTransaction(id, nc); } catch (DeadlockException d) { timestamp.stamp(); overseer.abort(id); timestamp.stamp(); throw new TransactionAbortedException(timestamp); } catch (TransactionAbortedException tae) { tae.t = timestamp; throw tae; } catch (InvalidTransactionException ite) { ite.t = timestamp; throw ite; } result.timestamp.stamp(); return result; } }
/** * Overriden update. If time interval has passed the gunner fires and the timer is reset with new * random value. * * @param level reference */ public void update(Level level) { if (timestamp.havePassed(time)) { time = Randomizer.getRandomNumber(minTime, maxTime); getShip().fire(level); timestamp.reset(); } }
// Create a new flight, or add seats to existing flight // NOTE: if flightPrice <= 0 and the flight already exists, it maintains its current price public ReturnTuple<Boolean> addFlight( int id, int flightNum, int flightSeats, int flightPrice, Timestamp timestamp) throws RemoteException, TransactionAbortedException, InvalidTransactionException { if (!isMaster) { System.out.println("Slave retransmitting addFlight to master"); return this.getMaster().addFlight(id, flightNum, flightSeats, flightPrice, timestamp); } else { timestamp.stamp(); AddFlightRMICommand af = new AddFlightRMICommand(flightGroup, id, flightNum, flightSeats, flightPrice); af.setTimestampObject(timestamp); ReturnTuple<Boolean> result = null; try { overseer.validTransaction(id); lm.Lock(id, Flight.getKey(flightNum), af.getRequiredLock()); af.execute(); result = af.success; if (result.result) overseer.addCommandToTransaction(id, af); } catch (DeadlockException d) { timestamp.stamp(); overseer.abort(id); timestamp.stamp(); throw new TransactionAbortedException(timestamp); } catch (TransactionAbortedException tae) { tae.t = timestamp; throw tae; } catch (InvalidTransactionException ite) { ite.t = timestamp; throw ite; } result.timestamp.stamp(); return result; } }
@Test public void ofDate1() { Date date = new Date(123456789); Timestamp time = Timestamp.of(date); assertThat(time.getSec(), equalTo(123456L)); assertThat(time.getNanoSec(), equalTo(789000000)); }
// Create a new car location or add cars to an existing location // NOTE: if price <= 0 and the location already exists, it maintains its current price public ReturnTuple<Boolean> addCars( int id, String location, int count, int price, Timestamp timestamp) throws RemoteException, TransactionAbortedException, InvalidTransactionException { if (!isMaster) { System.out.println("Slave retransmitting addCars to master"); return this.getMaster().addCars(id, location, count, price, timestamp); } else { timestamp.stamp(); AddCarsRMICommand ac = new AddCarsRMICommand(carGroup, id, location, count, price); ac.setTimestampObject(timestamp); ReturnTuple<Boolean> result = null; try { overseer.validTransaction(id); lm.Lock(id, Car.getKey(location), ac.getRequiredLock()); ac.execute(); result = ac.success; if (result.result) overseer.addCommandToTransaction(id, ac); } catch (DeadlockException d) { timestamp.stamp(); overseer.abort(id); timestamp.stamp(); throw new TransactionAbortedException(timestamp); } catch (TransactionAbortedException tae) { tae.t = timestamp; throw tae; } catch (InvalidTransactionException ite) { ite.t = timestamp; throw ite; } result.timestamp.stamp(); return result; } }
// Returns the number of empty seats on this flight public ReturnTuple<Integer> queryFlight(int id, int flightNum, Timestamp timestamp) throws RemoteException, TransactionAbortedException, InvalidTransactionException { if (!isMaster) { System.out.println("Slave retransmitting queryFlight to master"); return this.getMaster().queryFlight(id, flightNum, timestamp); } else { timestamp.stamp(); QueryFlightRMICommand qf = new QueryFlightRMICommand(flightGroup, id, flightNum); qf.setTimestampObject(timestamp); ReturnTuple<Integer> result = null; try { overseer.validTransaction(id); lm.Lock(id, Flight.getKey(flightNum), qf.getRequiredLock()); qf.execute(); result = qf.numSeats; } catch (DeadlockException d) { timestamp.stamp(); overseer.abort(id); timestamp.stamp(); throw new TransactionAbortedException(timestamp); } catch (TransactionAbortedException tae) { tae.t = timestamp; throw tae; } catch (InvalidTransactionException ite) { ite.t = timestamp; throw ite; } result.timestamp.stamp(); return result; } }
@Test public void durationFrom4() { Timestamp reference = Timestamp.of(10, 500000000); assertThat( reference.minus(TimeDuration.ofMillis(600)).durationFrom(reference), equalTo(TimeDuration.ofMillis(-600))); }
@Test public void durationFrom2() { Timestamp reference = Timestamp.now(); assertThat( reference.minus(TimeDuration.ofNanos(10)).durationFrom(reference), equalTo(TimeDuration.ofNanos(-10))); }
@Test public void durationBetween2() { Timestamp reference = Timestamp.now(); assertThat( reference.durationBetween(reference.minus(TimeDuration.ofNanos(10))), equalTo(TimeDuration.ofNanos(10))); }
// Returns price of cars at this location public ReturnTuple<Integer> queryCarsPrice(int id, String location, Timestamp timestamp) throws RemoteException, TransactionAbortedException, InvalidTransactionException { if (!isMaster) { System.out.println("Slave retransmitting queryCarsPrice to master"); return this.getMaster().queryCarsPrice(id, location, timestamp); } else { QueryCarsPriceRMICommand qcp = new QueryCarsPriceRMICommand(roomGroup, id, location); qcp.setTimestampObject(timestamp); ReturnTuple<Integer> result = null; try { overseer.validTransaction(id); lm.Lock(id, Car.getKey(location), qcp.getRequiredLock()); qcp.execute(); result = qcp.price; } catch (DeadlockException d) { timestamp.stamp(); overseer.abort(id); timestamp.stamp(); throw new TransactionAbortedException(timestamp); } catch (TransactionAbortedException tae) { tae.t = timestamp; throw tae; } catch (InvalidTransactionException ite) { ite.t = timestamp; throw ite; } result.timestamp.stamp(); return result; } }
// Delete rooms from a location public ReturnTuple<Boolean> deleteRooms(int id, String location, Timestamp timestamp) throws RemoteException, TransactionAbortedException, InvalidTransactionException { if (!isMaster) { System.out.println("Slave retransmitting deleteRooms to master"); return this.getMaster().deleteRooms(id, location, timestamp); } else { timestamp.stamp(); DeleteRoomsRMICommand dr = new DeleteRoomsRMICommand(roomGroup, id, location); dr.setTimestampObject(timestamp); ReturnTuple<Boolean> result = null; try { overseer.validTransaction(id); lm.Lock(id, Hotel.getKey(location), dr.getRequiredLock()); dr.execute(); result = dr.success; if (result.result) overseer.addCommandToTransaction(id, dr); } catch (DeadlockException d) { timestamp.stamp(); overseer.abort(id); timestamp.stamp(); throw new TransactionAbortedException(timestamp); } catch (TransactionAbortedException tae) { tae.t = timestamp; throw tae; } catch (InvalidTransactionException ite) { ite.t = timestamp; throw ite; } result.timestamp.stamp(); return result; } }
@Test public void durationBetween4() { Timestamp reference = Timestamp.of(10, 500000000); assertThat( reference.durationBetween(reference.minus(TimeDuration.ofMillis(600))), equalTo(TimeDuration.ofMillis(600))); }
// Deletes customer from the database. public ReturnTuple<Boolean> deleteCustomer(int id, int customerID, Timestamp timestamp) throws RemoteException, TransactionAbortedException, InvalidTransactionException { if (!isMaster) { System.out.println("Slave retransmitting deleteCustomer to master"); return this.getMaster().deleteCustomer(id, customerID, timestamp); } else { timestamp.stamp(); DeleteCustomerRMICommand dc = new DeleteCustomerRMICommand(carGroup, flightGroup, roomGroup, id, customerID); dc.setTimestampObject(timestamp); ReturnTuple<Boolean> result = null; try { overseer.validTransaction(id); lm.Lock(id, Customer.getKey(customerID), dc.getRequiredLock()); dc.execute(); result = dc.success; if (result.result) overseer.addCommandToTransaction(id, dc); } catch (DeadlockException d) { timestamp.stamp(); overseer.abort(id); timestamp.stamp(); throw new TransactionAbortedException(timestamp); } catch (TransactionAbortedException tae) { tae.t = timestamp; throw tae; } catch (InvalidTransactionException ite) { ite.t = timestamp; throw ite; } result.timestamp.stamp(); return result; } }
@Test public void ofDate2() { Date date = new Date(-123456789); Timestamp time = Timestamp.of(date); assertThat(time.toDate(), equalTo(date)); assertThat(time.getSec(), equalTo(-123457L)); assertThat(time.getNanoSec(), equalTo(211000000)); }
/** {@inheritDoc} */ @Before public void setUp() { ts = new Timestamp(); ts.setNodeId("node1"); ts.setSeqNumber(10); theSummary = new Summary(); setInternalState(theSummary, data); }
public ReturnTuple<Integer> start(Timestamp timestamp) throws RemoteException { if (!isMaster) { System.out.println("Slave retransmitting start to master"); return this.getMaster().start(timestamp); } else { timestamp.stamp(); int tId; tId = overseer.createTransaction(lm); timestamp.stamp(); return new ReturnTuple<Integer>(tId, timestamp); } }
public ReturnTuple<Boolean> commit(int id, Timestamp timestamp) throws RemoteException, TransactionAbortedException, InvalidTransactionException { if (!isMaster) { System.out.println("Slave retransmitting commit to master"); return this.getMaster().commit(id, timestamp); } else { timestamp.stamp(); boolean result = overseer.commit(id); timestamp.stamp(); return new ReturnTuple<Boolean>(result, timestamp); } }
public ReturnTuple<Object> abort(int id, Timestamp timestamp) throws RemoteException, TransactionAbortedException, InvalidTransactionException { if (!isMaster) { System.out.println("Slave retransmitting abort to master"); return this.getMaster().abort(id, timestamp); } else { timestamp.stamp(); overseer.abort(id); timestamp.stamp(); return new ReturnTuple<Object>(null, timestamp); } }
private void isRiverStale(DBCursor cursor, Timestamp<?> time) throws SlurperException { if (cursor == null || time == null) { return; } if (definition.getInitialTimestamp() != null && time.equals(definition.getInitialTimestamp())) { return; } DBObject entry = cursor.next(); Timestamp<?> oplogTimestamp = Timestamp.on(entry); if (!time.equals(oplogTimestamp)) { MongoDBRiverHelper.setRiverStatus(client, definition.getRiverName(), Status.RIVER_STALE); throw new SlurperException("River out of sync with oplog.rs collection"); } }
/** * Test for the {@link * org.coderebels.tsaenode.core.common.Summary#update(org.coderebels.tsaenode.core.common.Timestamp)} * method when timestamp has already been summarized */ @Test public void testUpdate_timestampAlreadySummarized() { String nodeId = ts.getNodeId(); Timestamp last = new Timestamp(); last.setNodeId(nodeId); last.setSeqNumber(100); doReturn(last).when(data).get(nodeId); theSummary.update(ts); verify(data, never()).put(nodeId, ts); }
/* reserve an itinerary */ public ReturnTuple<Boolean> itinerary( int id, int customer, Vector flightNumbers, String location, boolean Car, boolean Room, Timestamp timestamp) throws RemoteException, TransactionAbortedException, InvalidTransactionException { if (!isMaster) { System.out.println("Slave retransmitting itinerary to master"); return this.getMaster() .itinerary(id, customer, flightNumbers, location, Car, Room, timestamp); } else { timestamp.stamp(); ItineraryRMICommand i = new ItineraryRMICommand( carGroup, flightGroup, roomGroup, id, customer, flightNumbers, location, Car, Room); i.setTimestampObject(timestamp); ReturnTuple<Boolean> result = null; try { overseer.validTransaction(id); lm.Lock(id, Customer.getKey(customer), i.getRequiredLock()); lm.Lock(id, ResImpl.Car.getKey(location), i.getRequiredLock()); lm.Lock(id, Hotel.getKey(location), i.getRequiredLock()); for (Object flightNo : flightNumbers) { int flightNum = Integer.parseInt((String) flightNo); lm.Lock(id, Flight.getKey(flightNum), i.getRequiredLock()); } i.execute(); result = i.success; if (result.result && !i.error()) overseer.addCommandToTransaction(id, i); } catch (DeadlockException d) { timestamp.stamp(); overseer.abort(id); timestamp.stamp(); throw new TransactionAbortedException(timestamp); } catch (TransactionAbortedException tae) { tae.t = timestamp; throw tae; } catch (InvalidTransactionException ite) { ite.t = timestamp; throw ite; } result.timestamp.stamp(); return result; } }
// return a bill public ReturnTuple<String> queryCustomerInfo(int id, int customerID, Timestamp timestamp) throws RemoteException, TransactionAbortedException, InvalidTransactionException { if (!isMaster) { System.out.println("Slave retransmitting queryCustomerInfo to master"); return this.getMaster().queryCustomerInfo(id, customerID, timestamp); } else { timestamp.stamp(); QueryCustomerInfoRMICommand qci = new QueryCustomerInfoRMICommand(carGroup, flightGroup, roomGroup, id, customerID); qci.setTimestampObject(timestamp); ReturnTuple<String> result = null; try { Vector<Integer> flightNos; Vector<String> locations; overseer.validTransaction(id); lm.Lock(id, Customer.getKey(customerID), qci.getRequiredLock()); qci.execute(); flightNos = qci.getCustomerFlightReservations(); for (int flightNo : flightNos) { lm.Lock(id, Flight.getKey(flightNo), qci.getRequiredLock()); } locations = qci.getCustomerRoomReservations(); for (String location : locations) { lm.Lock(id, Hotel.getKey(location), qci.getRequiredLock()); } locations = qci.getCustomerCarReservations(); for (String location : locations) { lm.Lock(id, Car.getKey(location), qci.getRequiredLock()); } qci.execute(); result = qci.customerInfo; } catch (DeadlockException d) { timestamp.stamp(); overseer.abort(id); timestamp.stamp(); throw new TransactionAbortedException(timestamp); } catch (TransactionAbortedException tae) { tae.t = timestamp; throw tae; } catch (InvalidTransactionException ite) { ite.t = timestamp; throw ite; } result.timestamp.stamp(); return result; } }
public static void output(String name, String str, boolean useColors) { String toDisplay = (YELLOW + name + ": " + BRIGHT_WHITE + Timestamp.getTimestamp() + PLAIN + str + PLAIN); if (useColors == false) toDisplay = toDisplay.replaceAll("\\" + ((char) 27) + ".*?m", ""); System.out.println(toDisplay); }
private Timestamp<?> getCurrentOplogTimestamp() { return Timestamp.on( oplogCollection .find() .sort(new BasicDBObject(MongoDBRiver.INSERTION_ORDER_KEY, -1)) .limit(1) .next()); }
/** * Returns the hash code value for this code signer. The hash code is generated using the signer's * certificate path and the timestamp, if present. * * @return a hash code value for this code signer. */ public int hashCode() { if (myhash == -1) { if (timestamp == null) { myhash = signerCertPath.hashCode(); } else { myhash = signerCertPath.hashCode() + timestamp.hashCode(); } } return myhash; }
@Override protected final void entityLoad(EntityFields data) { username = (String) data.get("username"); encodedpassword = (String) data.get("encodedpassword"); usercode = (String) data.get("usercode"); enabled = (Boolean) data.get("enabled"); id = (Integer) data.get("id"); createdby = (String) data.get("createdby"); try { createdon.setDateUsingSQLString((String) data.get("createdon")); } catch (BadFormatException ex) { throw new LogicException("Load reported bad Timestamp format - should never happen!!"); } updatedby = (String) data.get("updatedby"); try { updatedon.setDateUsingSQLString((String) data.get("updatedon")); } catch (BadFormatException ex) { throw new LogicException("Load reported bad Timestamp format - should never happen!!"); } }
private DBCursor oplogCursor(final Timestamp<?> timestampOverride) throws SlurperException { Timestamp<?> time = timestampOverride == null ? MongoDBRiver.getLastTimestamp(client, definition) : timestampOverride; DBObject indexFilter = time.getOplogFilter(); if (indexFilter == null) { return null; } int options = Bytes.QUERYOPTION_TAILABLE | Bytes.QUERYOPTION_AWAITDATA | Bytes.QUERYOPTION_NOTIMEOUT; // Using OPLOGREPLAY to improve performance: // https://jira.mongodb.org/browse/JAVA-771 if (indexFilter.containsField(MongoDBRiver.OPLOG_TIMESTAMP)) { options = options | Bytes.QUERYOPTION_OPLOGREPLAY; } DBCursor cursor = oplogCollection.find(indexFilter).setOptions(options); isRiverStale(cursor, time); return cursor; }
/** * Tests for equality between the specified object and this code signer. Two code signers are * considered equal if their signer certificate paths are equal and if their timestamps are equal, * if present in both. * * @param obj the object to test for equality with this object. * @return true if the objects are considered equal, false otherwise. */ public boolean equals(Object obj) { if (obj == null || (!(obj instanceof CodeSigner))) { return false; } CodeSigner that = (CodeSigner) obj; if (this == that) { return true; } Timestamp thatTimestamp = that.getTimestamp(); if (timestamp == null) { if (thatTimestamp != null) { return false; } } else { if (thatTimestamp == null || (!timestamp.equals(thatTimestamp))) { return false; } } return signerCertPath.equals(that.getSignerCertPath()); }
@Test public void testHistoricalBrowseRecordIsSameAsHistoricalFetchDescribe() { long record = TestData.getLong(); client.add("a", 1, record); client.add("a", 2, record); client.add("a", 3, record); client.add("b", 1, record); client.add("b", 2, record); client.add("b", 3, record); client.remove("a", 2, record); Timestamp timestamp = Timestamp.now(); client.add("c", 1, record); client.add("c", 2, record); client.add("c", 3, record); client.add("d", 1, record); client.add("d", 2, record); client.add("d", 3, record); client.remove("c", 2, record); Assert.assertEquals( client.browse(record, timestamp), client.fetch(client.describe(record, timestamp), record, timestamp)); }
public boolean equals(Timestamp ts) { return ts != null && getTime() == ts.getTime() && getNanos() == ts.getNanos(); }