use of cbit.vcell.message.server.ServiceStatus in project vcell by virtualcell.
the class AdminDBTopLevel method updateServiceStatus.
public ServiceStatus updateServiceStatus(ServiceStatus oldServiceStatus, TransactionalServiceOperation serviceOP, boolean bEnableRetry) throws SQLException, UpdateSynchronizationException {
Object lock = new Object();
Connection con = conFactory.getConnection(lock);
try {
ServiceStatus currentServiceStatus = serviceStatusDB.getServiceStatus(con, oldServiceStatus.getServiceSpec().getServerID(), oldServiceStatus.getServiceSpec().getType(), oldServiceStatus.getServiceSpec().getOrdinal(), true);
if (!currentServiceStatus.compareEqual(oldServiceStatus)) {
throw new UpdateSynchronizationException("current service status " + currentServiceStatus + " doesn't match argument for " + oldServiceStatus);
}
ServiceStatus newServiceStatus = null;
try {
newServiceStatus = serviceOP.doOperation(oldServiceStatus);
} catch (Exception ex) {
lg.error("failure in updateServiceStatus()", ex);
throw new RuntimeException("transactional operation failed for " + newServiceStatus + " : " + ex.getMessage());
}
serviceStatusDB.updateServiceStatus(con, newServiceStatus);
con.commit();
ServiceStatus updatedServiceStatus = serviceStatusDB.getServiceStatus(con, oldServiceStatus.getServiceSpec().getServerID(), oldServiceStatus.getServiceSpec().getType(), oldServiceStatus.getServiceSpec().getOrdinal(), false);
return updatedServiceStatus;
} catch (Throwable e) {
lg.error("failure in updateServiceStatus()", e);
try {
con.rollback();
} catch (Throwable rbe) {
lg.error("exception during rollback, bEnableRetry = " + bEnableRetry, rbe);
}
if (bEnableRetry && isBadConnection(con)) {
conFactory.failed(con, lock);
return updateServiceStatus(oldServiceStatus, serviceOP, false);
} else {
handle_SQLException(e);
// never gets here;
return null;
}
} finally {
conFactory.release(con, lock);
}
}
use of cbit.vcell.message.server.ServiceStatus in project vcell by virtualcell.
the class AdminDBTopLevel method insertServiceStatus.
public ServiceStatus insertServiceStatus(ServiceStatus serviceStatus, boolean bEnableRetry) throws SQLException, UpdateSynchronizationException {
Object lock = new Object();
Connection con = conFactory.getConnection(lock);
try {
ServiceStatus currentServiceStatus = serviceStatusDB.getServiceStatus(con, serviceStatus.getServiceSpec().getServerID(), serviceStatus.getServiceSpec().getType(), serviceStatus.getServiceSpec().getOrdinal(), false);
if (currentServiceStatus != null) {
throw new UpdateSynchronizationException("service already exists:" + currentServiceStatus);
}
serviceStatusDB.insertServiceStatus(con, serviceStatus, conFactory.getKeyFactory().getNewKey(con));
con.commit();
ServiceStatus newServiceStatus = serviceStatusDB.getServiceStatus(con, serviceStatus.getServiceSpec().getServerID(), serviceStatus.getServiceSpec().getType(), serviceStatus.getServiceSpec().getOrdinal(), false);
return newServiceStatus;
} catch (Throwable e) {
lg.error("failure in insertServiceStatus()", e);
try {
con.rollback();
} catch (Throwable rbe) {
lg.error("exception during rollback, bEnableRetry = " + bEnableRetry, rbe);
}
if (bEnableRetry && isBadConnection(con)) {
conFactory.failed(con, lock);
return insertServiceStatus(serviceStatus, false);
} else {
handle_SQLException(e);
// never gets here;
return null;
}
} finally {
conFactory.release(con, lock);
}
}
use of cbit.vcell.message.server.ServiceStatus in project vcell by virtualcell.
the class AdminDBTopLevel method deleteServiceStatus.
public void deleteServiceStatus(ServiceStatus serviceStatus, boolean bEnableRetry) throws SQLException, UpdateSynchronizationException {
Object lock = new Object();
Connection con = conFactory.getConnection(lock);
try {
ServiceStatus currentServiceStatus = serviceStatusDB.getServiceStatus(con, serviceStatus.getServiceSpec().getServerID(), serviceStatus.getServiceSpec().getType(), serviceStatus.getServiceSpec().getOrdinal(), false);
if (currentServiceStatus == null) {
throw new UpdateSynchronizationException("service doesn't exist:" + currentServiceStatus);
}
serviceStatusDB.deleteServiceStatus(con, serviceStatus, conFactory.getKeyFactory().getNewKey(con));
con.commit();
} catch (Throwable e) {
lg.error("failure in deleteServiceStatus()", e);
try {
con.rollback();
} catch (Throwable rbe) {
lg.error("exception during rollback, bEnableRetry = " + bEnableRetry, rbe);
}
if (bEnableRetry && isBadConnection(con)) {
conFactory.failed(con, lock);
deleteServiceStatus(serviceStatus, false);
} else {
handle_SQLException(e);
}
} finally {
conFactory.release(con, lock);
}
}
Aggregations