Search in sources :

Example 1 with DistributedLockManager

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;
}
Also used : DistributedAttachmentManager(jgnash.engine.attachment.DistributedAttachmentManager) DistributedLockManager(jgnash.engine.concurrent.DistributedLockManager) Properties(java.util.Properties) Engine(jgnash.engine.Engine) SQLException(java.sql.SQLException) IOException(java.io.IOException) EngineException(jgnash.engine.EngineException)

Example 2 with DistributedLockManager

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;
}
Also used : DistributedAttachmentManager(jgnash.engine.attachment.DistributedAttachmentManager) DistributedLockManager(jgnash.engine.concurrent.DistributedLockManager) Properties(java.util.Properties) Engine(jgnash.engine.Engine) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 3 with DistributedLockManager

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);
}
Also used : DistributedLockServer(jgnash.engine.concurrent.DistributedLockServer) DistributedLockManager(jgnash.engine.concurrent.DistributedLockManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with DistributedLockManager

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);
}
Also used : DistributedLockServer(jgnash.engine.concurrent.DistributedLockServer) DistributedLockManager(jgnash.engine.concurrent.DistributedLockManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

DistributedLockManager (jgnash.engine.concurrent.DistributedLockManager)4 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 Engine (jgnash.engine.Engine)2 DistributedAttachmentManager (jgnash.engine.attachment.DistributedAttachmentManager)2 DistributedLockServer (jgnash.engine.concurrent.DistributedLockServer)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 EngineException (jgnash.engine.EngineException)1