use of jgnash.engine.concurrent.DistributedLockManager in project jgnash by ccavanaugh.
the class JpaNetworkServer method createEngine.
private Engine createEngine(final DataStoreType dataStoreType, final String fileName, final int port, final char[] password) {
final Properties properties = JpaConfiguration.getClientProperties(dataStoreType, fileName, EngineFactory.LOCALHOST, port, password);
logger.log(Level.INFO, "Local connection url is: {0}", properties.getProperty(JpaConfiguration.JAVAX_PERSISTENCE_JDBC_URL));
Engine engine = null;
try {
// An exception will be thrown if the password is not correct, or the database did not have a password
if (SqlUtils.isConnectionValid(properties.getProperty(JpaConfiguration.JAVAX_PERSISTENCE_JDBC_URL))) {
/* specifies the unit name and properties. Unit name can be used to specify a different persistence
unit defined in persistence.xml */
factory = Persistence.createEntityManagerFactory(JpaConfiguration.UNIT_NAME, properties);
em = factory.createEntityManager();
distributedLockManager = new DistributedLockManager(EngineFactory.LOCALHOST, port + LOCK_SERVER_INCREMENT);
distributedLockManager.connectToServer(password);
distributedAttachmentManager = new DistributedAttachmentManager(EngineFactory.LOCALHOST, port + TRANSFER_SERVER_INCREMENT);
distributedAttachmentManager.connectToServer(password);
logger.info("Created local JPA container and engine");
engine = new Engine(new JpaEngineDAO(em, true), distributedLockManager, distributedAttachmentManager, // treat as a remote engine
SERVER_ENGINE);
}
} catch (final Exception e) {
logger.log(Level.SEVERE, e.toString(), e);
}
return engine;
}
use of jgnash.engine.concurrent.DistributedLockManager in project jgnash by ccavanaugh.
the class AbstractJpaDataStore method getClientEngine.
@Override
public Engine getClientEngine(final String host, final int port, final char[] password, final String dataBasePath) {
final Properties properties = JpaConfiguration.getClientProperties(getType(), dataBasePath, host, port, password);
Engine engine = null;
try {
if (SqlUtils.isConnectionValid(properties.getProperty(JpaConfiguration.JAVAX_PERSISTENCE_JDBC_URL))) {
factory = Persistence.createEntityManagerFactory(JpaConfiguration.UNIT_NAME, properties);
em = factory.createEntityManager();
if (em != null) {
distributedLockManager = new DistributedLockManager(host, port + JpaNetworkServer.LOCK_SERVER_INCREMENT);
boolean lockManagerResult = distributedLockManager.connectToServer(password);
distributedAttachmentManager = new DistributedAttachmentManager(host, port + JpaNetworkServer.TRANSFER_SERVER_INCREMENT);
boolean attachmentManagerResult = distributedAttachmentManager.connectToServer(password);
if (attachmentManagerResult && lockManagerResult) {
engine = new Engine(new JpaEngineDAO(em, true), distributedLockManager, distributedAttachmentManager, EngineFactory.DEFAULT);
logger.info("Created local JPA container and engine");
fileName = null;
local = false;
} else {
distributedLockManager.disconnectFromServer();
distributedAttachmentManager.disconnectFromServer();
em.close();
factory.close();
em = null;
factory = null;
}
}
}
} catch (final Exception e) {
logger.log(Level.SEVERE, e.toString(), e);
}
return engine;
}
use of jgnash.engine.concurrent.DistributedLockManager in project jgnash by ccavanaugh.
the class EncryptedDistributedLockTest method setUp.
@BeforeEach
@Override
public void setUp() {
final char[] password = new char[] { 'P', 'a', 's', 's', 'w', 'o', 'r', 'd' };
// System.setProperty(EncryptionManager.ENCRYPTION_FLAG, "true");
// System.setProperty("ssl", "true");
server = new DistributedLockServer(PORT);
assertTrue(server.startServer(password));
manager = new DistributedLockManager(EngineFactory.LOCALHOST, PORT);
manager.connectToServer(password);
}
use of jgnash.engine.concurrent.DistributedLockManager in project jgnash by ccavanaugh.
the class DistributedLockTest method setUp.
@BeforeEach
public void setUp() {
server = new DistributedLockServer(PORT);
assertTrue(server.startServer(EngineFactory.EMPTY_PASSWORD));
manager = new DistributedLockManager(EngineFactory.LOCALHOST, PORT);
manager.connectToServer(EngineFactory.EMPTY_PASSWORD);
}
Aggregations