Example usage for java.util.concurrent.locks ReentrantLock lock

List of usage examples for java.util.concurrent.locks ReentrantLock lock

Introduction

In this page you can find the example usage for java.util.concurrent.locks ReentrantLock lock.

Prototype

public void lock() 

Source Link

Document

Acquires the lock.

Usage

From source file:org.apache.openejb.resource.jdbc.dbcp.BasicDataSource.java

public void setDefaultTransactionIsolation(final String s) {
    final ReentrantLock l = lock;
    l.lock();
    try {/*from ww w. j ava  2 s.co  m*/
        if (s == null || s.equals("")) {
            return;
        }
        final int level = IsolationLevels.getIsolationLevel(s);
        super.setDefaultTransactionIsolation(level);
    } finally {
        l.unlock();
    }
}

From source file:org.apache.openejb.resource.jdbc.dbcp.BasicManagedDataSource.java

public Logger getParentLogger() throws SQLFeatureNotSupportedException {
    final ReentrantLock l = lock;
    l.lock();
    try {// w  w  w  .  j a va2s  .  c  o m

        if (null == this.logger) {
            this.logger = (Logger) DataSource.class.getDeclaredMethod("getParentLogger")
                    .invoke(super.dataSource);
        }

        return this.logger;
    } catch (final Throwable e) {
        throw new SQLFeatureNotSupportedException();
    } finally {
        l.unlock();
    }
}

From source file:org.apache.openejb.resource.jdbc.dbcp.BasicDataSource.java

public void close() throws SQLException {
    //TODO - Prevent unuathorized call
    final ReentrantLock l = lock;
    l.lock();
    try {//from  www .j av  a 2s  . c om
        try {
            unregisterMBean();
        } catch (final Exception ignored) {
            // no-op
        }

        super.close();
    } finally {
        l.unlock();
    }
}

From source file:org.apache.openejb.resource.jdbc.dbcp.BasicDataSource.java

public Logger getParentLogger() throws SQLFeatureNotSupportedException {
    final ReentrantLock l = lock;
    l.lock();
    try {// ww w . j a  v a 2 s.  c om

        if (null == this.logger) {
            this.logger = (Logger) Reflections.invokeByReflection(super.dataSource, "getParentLogger",
                    new Class<?>[0], null);
        }

        return this.logger;
    } catch (final Throwable e) {
        throw new SQLFeatureNotSupportedException();
    } finally {
        l.unlock();
    }
}

From source file:org.commoncrawl.service.parser.client.Dispatcher.java

public void nodeOffline(ParserNode theNode) {
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {/*from  ww  w . ja va  2  s  .c  om*/
        _onlineNodes.remove(theNode);
    } finally {
        lock.unlock();
    }
}

From source file:org.commoncrawl.service.parser.client.Dispatcher.java

public void nodeOnline(ParserNode theNode) throws IOException {
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {/*from   ww  w . j a v a 2  s . c  o m*/
        boolean ok = _onlineNodes.add(theNode);
        assert ok;
        notEmpty.signal();
    } finally {
        lock.unlock();
    }
}

From source file:org.commoncrawl.service.parser.client.Dispatcher.java

public void nodeStatusChanged(ParserNode theNode) {
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {/* ww w  .ja  va 2s.c  o m*/
        _onlineNodes.remove(theNode);
        _onlineNodes.add(theNode);
        notEmpty.signal();
    } finally {
        lock.unlock();
    }
}

From source file:org.commoncrawl.service.parser.client.Dispatcher.java

public ParserNode take() {
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {//from w ww . jav a 2 s  .  c om
        try {
            while (_onlineNodes.size() == 0)
                notEmpty.await();
        } catch (InterruptedException ie) {
            if (online.get()) {
                notEmpty.signal(); // propagate to non-interrupted thread
            }
        }
        ParserNode x = _onlineNodes.poll();
        x.touch();
        assert x != null;
        _onlineNodes.add(x);
        return x;
    } finally {
        lock.unlock();
    }
}

From source file:org.apache.openejb.resource.jdbc.dbcp.BasicManagedDataSource.java

protected DataSource createDataSource() throws SQLException {
    final ReentrantLock l = lock;
    l.lock();
    try {//from  w  w w  .  j a  va 2  s  .com
        if (super.dataSource != null) {
            return super.dataSource;
        }

        // check password codec if available
        if (null != passwordCipher) {
            final PasswordCipher cipher = PasswordCipherFactory.getPasswordCipher(passwordCipher);
            final String plainPwd = cipher.decrypt(password.toCharArray());

            // override previous password value
            super.setPassword(plainPwd);
        }

        // get the plugin
        final DataSourcePlugin helper = BasicDataSourceUtil.getDataSourcePlugin(getUrl());

        // configure this
        if (helper != null) {
            final String currentUrl = getUrl();
            final String newUrl = helper.updatedUrl(currentUrl);
            if (!currentUrl.equals(newUrl)) {
                super.setUrl(newUrl);
            }
        }

        wrapTransactionManager();
        // create the data source
        if (helper == null || !helper.enableUserDirHack()) {
            try {
                return super.createDataSource();
            } catch (final Throwable e) {
                throw BasicDataSource.toSQLException(e);
            }
        } else {
            // wrap super call with code that sets user.dir to openejb.base and then resets it
            final Properties systemProperties = System.getProperties();

            final String userDir = systemProperties.getProperty("user.dir");
            try {
                final File base = SystemInstance.get().getBase().getDirectory();
                systemProperties.setProperty("user.dir", base.getAbsolutePath());
                try {
                    return super.createDataSource();
                } catch (final Throwable e) {
                    throw BasicDataSource.toSQLException(e);
                }
            } finally {
                systemProperties.setProperty("user.dir", userDir);
            }

        }
    } finally {
        l.unlock();
    }
}

From source file:org.apache.openejb.resource.jdbc.dbcp.BasicDataSource.java

protected DataSource createDataSource() throws SQLException {
    final ReentrantLock l = lock;
    l.lock();
    try {/*  w  w  w . j  a v  a  2 s  . co m*/
        if (super.dataSource != null) {
            return super.dataSource;
        }

        // check password codec if available
        if (null != passwordCipher) {
            final PasswordCipher cipher = PasswordCipherFactory.getPasswordCipher(passwordCipher);
            final String plainPwd = cipher.decrypt(password.toCharArray());

            // override previous password value
            super.setPassword(plainPwd);
        }

        // get the plugin
        final DataSourcePlugin helper = BasicDataSourceUtil.getDataSourcePlugin(getUrl());

        // configure this
        if (helper != null) {
            final String currentUrl = getUrl();
            final String newUrl = helper.updatedUrl(currentUrl);
            if (!currentUrl.equals(newUrl)) {
                super.setUrl(newUrl);
            }
        }

        // create the data source
        if (helper == null || !helper.enableUserDirHack()) {
            try {
                return super.createDataSource();
            } catch (final Throwable e) {
                throw toSQLException(e);
            }
        } else {
            // wrap super call with code that sets user.dir to openejb.base and then resets it
            final Properties systemProperties = System.getProperties();

            final String userDir = systemProperties.getProperty("user.dir");
            try {
                final File base = SystemInstance.get().getBase().getDirectory();
                systemProperties.setProperty("user.dir", base.getAbsolutePath());
                try {
                    return super.createDataSource();
                } catch (final Throwable e) {
                    throw toSQLException(e);
                }
            } finally {
                systemProperties.setProperty("user.dir", userDir);
            }

        }
    } finally {
        l.unlock();
    }
}