Java Code Examples for com.sun.corba.se.pept.transport.Connection#close()

The following examples show how to use com.sun.corba.se.pept.transport.Connection#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CorbaConnectionCacheBase.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Discarding least recently used Connections that are not busy
 *
 * This method must be synchronized since one WorkerThread could
 * be reclaming connections inside the synchronized backingStore
 * block and a second WorkerThread (or a SelectorThread) could have
 * already executed the if (numberOfConnections <= .... ). As a
 * result the second thread would also attempt to reclaim connections.
 *
 * If connection reclamation becomes a performance issue, the connection
 * reclamation could make its own task and consequently executed in
 * a separate thread.
 * Currently, the accept & reclaim are done in the same thread, WorkerThread
 * by default. It could be changed such that the SelectorThread would do
 * it for SocketChannels and WorkerThreads for Sockets by updating the
 * ParserTable.
 */
synchronized public boolean reclaim()
{
    try {
        long numberOfConnections = numberOfConnections();

        if (orb.transportDebugFlag) {
            dprint(".reclaim->: " + numberOfConnections
                    + " ("
                    + orb.getORBData().getHighWaterMark()
                    + "/"
                    + orb.getORBData().getLowWaterMark()
                    + "/"
                    + orb.getORBData().getNumberToReclaim()
                    + ")");
        }

        if (numberOfConnections <= orb.getORBData().getHighWaterMark() ||
            numberOfConnections < orb.getORBData().getLowWaterMark()) {
            return false;
        }

        Object backingStore = backingStore();
        synchronized (backingStore) {

             // REVISIT - A less expensive alternative connection reclaiming
             //           algorithm could be investigated.

            for (int i=0; i < orb.getORBData().getNumberToReclaim(); i++) {
                Connection toClose = null;
                long lru = java.lang.Long.MAX_VALUE;
                Iterator iterator = values().iterator();

                // Find least recently used and not busy connection in cache
                while ( iterator.hasNext() ) {
                    Connection c = (Connection) iterator.next();
                    if ( !c.isBusy() && c.getTimeStamp() < lru ) {
                        toClose = c;
                        lru = c.getTimeStamp();
                    }
                }

                if ( toClose == null ) {
                    return false;
                }

                try {
                    if (orb.transportDebugFlag) {
                        dprint(".reclaim: closing: " + toClose);
                    }
                    toClose.close();
                } catch (Exception ex) {
                    // REVISIT - log
                }
            }

            if (orb.transportDebugFlag) {
                dprint(".reclaim: connections reclaimed ("
                        + (numberOfConnections - numberOfConnections()) + ")");
            }
        }

        // XXX is necessary to do a GC to reclaim
        // closed network connections ??
        // java.lang.System.gc();

        return true;
    } finally {
        if (orb.transportDebugFlag) {
            dprint(".reclaim<-: " + numberOfConnections());
        }
    }
}
 
Example 2
Source File: CorbaConnectionCacheBase.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Discarding least recently used Connections that are not busy
 *
 * This method must be synchronized since one WorkerThread could
 * be reclaming connections inside the synchronized backingStore
 * block and a second WorkerThread (or a SelectorThread) could have
 * already executed the if (numberOfConnections <= .... ). As a
 * result the second thread would also attempt to reclaim connections.
 *
 * If connection reclamation becomes a performance issue, the connection
 * reclamation could make its own task and consequently executed in
 * a separate thread.
 * Currently, the accept & reclaim are done in the same thread, WorkerThread
 * by default. It could be changed such that the SelectorThread would do
 * it for SocketChannels and WorkerThreads for Sockets by updating the
 * ParserTable.
 */
synchronized public boolean reclaim()
{
    try {
        long numberOfConnections = numberOfConnections();

        if (orb.transportDebugFlag) {
            dprint(".reclaim->: " + numberOfConnections
                    + " ("
                    + orb.getORBData().getHighWaterMark()
                    + "/"
                    + orb.getORBData().getLowWaterMark()
                    + "/"
                    + orb.getORBData().getNumberToReclaim()
                    + ")");
        }

        if (numberOfConnections <= orb.getORBData().getHighWaterMark() ||
            numberOfConnections < orb.getORBData().getLowWaterMark()) {
            return false;
        }

        Object backingStore = backingStore();
        synchronized (backingStore) {

             // REVISIT - A less expensive alternative connection reclaiming
             //           algorithm could be investigated.

            for (int i=0; i < orb.getORBData().getNumberToReclaim(); i++) {
                Connection toClose = null;
                long lru = java.lang.Long.MAX_VALUE;
                Iterator iterator = values().iterator();

                // Find least recently used and not busy connection in cache
                while ( iterator.hasNext() ) {
                    Connection c = (Connection) iterator.next();
                    if ( !c.isBusy() && c.getTimeStamp() < lru ) {
                        toClose = c;
                        lru = c.getTimeStamp();
                    }
                }

                if ( toClose == null ) {
                    return false;
                }

                try {
                    if (orb.transportDebugFlag) {
                        dprint(".reclaim: closing: " + toClose);
                    }
                    toClose.close();
                } catch (Exception ex) {
                    // REVISIT - log
                }
            }

            if (orb.transportDebugFlag) {
                dprint(".reclaim: connections reclaimed ("
                        + (numberOfConnections - numberOfConnections()) + ")");
            }
        }

        // XXX is necessary to do a GC to reclaim
        // closed network connections ??
        // java.lang.System.gc();

        return true;
    } finally {
        if (orb.transportDebugFlag) {
            dprint(".reclaim<-: " + numberOfConnections());
        }
    }
}
 
Example 3
Source File: CorbaConnectionCacheBase.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Discarding least recently used Connections that are not busy
 *
 * This method must be synchronized since one WorkerThread could
 * be reclaming connections inside the synchronized backingStore
 * block and a second WorkerThread (or a SelectorThread) could have
 * already executed the if (numberOfConnections <= .... ). As a
 * result the second thread would also attempt to reclaim connections.
 *
 * If connection reclamation becomes a performance issue, the connection
 * reclamation could make its own task and consequently executed in
 * a separate thread.
 * Currently, the accept & reclaim are done in the same thread, WorkerThread
 * by default. It could be changed such that the SelectorThread would do
 * it for SocketChannels and WorkerThreads for Sockets by updating the
 * ParserTable.
 */
synchronized public boolean reclaim()
{
    try {
        long numberOfConnections = numberOfConnections();

        if (orb.transportDebugFlag) {
            dprint(".reclaim->: " + numberOfConnections
                    + " ("
                    + orb.getORBData().getHighWaterMark()
                    + "/"
                    + orb.getORBData().getLowWaterMark()
                    + "/"
                    + orb.getORBData().getNumberToReclaim()
                    + ")");
        }

        if (numberOfConnections <= orb.getORBData().getHighWaterMark() ||
            numberOfConnections < orb.getORBData().getLowWaterMark()) {
            return false;
        }

        Object backingStore = backingStore();
        synchronized (backingStore) {

             // REVISIT - A less expensive alternative connection reclaiming
             //           algorithm could be investigated.

            for (int i=0; i < orb.getORBData().getNumberToReclaim(); i++) {
                Connection toClose = null;
                long lru = java.lang.Long.MAX_VALUE;
                Iterator iterator = values().iterator();

                // Find least recently used and not busy connection in cache
                while ( iterator.hasNext() ) {
                    Connection c = (Connection) iterator.next();
                    if ( !c.isBusy() && c.getTimeStamp() < lru ) {
                        toClose = c;
                        lru = c.getTimeStamp();
                    }
                }

                if ( toClose == null ) {
                    return false;
                }

                try {
                    if (orb.transportDebugFlag) {
                        dprint(".reclaim: closing: " + toClose);
                    }
                    toClose.close();
                } catch (Exception ex) {
                    // REVISIT - log
                }
            }

            if (orb.transportDebugFlag) {
                dprint(".reclaim: connections reclaimed ("
                        + (numberOfConnections - numberOfConnections()) + ")");
            }
        }

        // XXX is necessary to do a GC to reclaim
        // closed network connections ??
        // java.lang.System.gc();

        return true;
    } finally {
        if (orb.transportDebugFlag) {
            dprint(".reclaim<-: " + numberOfConnections());
        }
    }
}
 
Example 4
Source File: CorbaConnectionCacheBase.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Discarding least recently used Connections that are not busy
 *
 * This method must be synchronized since one WorkerThread could
 * be reclaming connections inside the synchronized backingStore
 * block and a second WorkerThread (or a SelectorThread) could have
 * already executed the if (numberOfConnections <= .... ). As a
 * result the second thread would also attempt to reclaim connections.
 *
 * If connection reclamation becomes a performance issue, the connection
 * reclamation could make its own task and consequently executed in
 * a separate thread.
 * Currently, the accept & reclaim are done in the same thread, WorkerThread
 * by default. It could be changed such that the SelectorThread would do
 * it for SocketChannels and WorkerThreads for Sockets by updating the
 * ParserTable.
 */
synchronized public boolean reclaim()
{
    try {
        long numberOfConnections = numberOfConnections();

        if (orb.transportDebugFlag) {
            dprint(".reclaim->: " + numberOfConnections
                    + " ("
                    + orb.getORBData().getHighWaterMark()
                    + "/"
                    + orb.getORBData().getLowWaterMark()
                    + "/"
                    + orb.getORBData().getNumberToReclaim()
                    + ")");
        }

        if (numberOfConnections <= orb.getORBData().getHighWaterMark() ||
            numberOfConnections < orb.getORBData().getLowWaterMark()) {
            return false;
        }

        Object backingStore = backingStore();
        synchronized (backingStore) {

             // REVISIT - A less expensive alternative connection reclaiming
             //           algorithm could be investigated.

            for (int i=0; i < orb.getORBData().getNumberToReclaim(); i++) {
                Connection toClose = null;
                long lru = java.lang.Long.MAX_VALUE;
                Iterator iterator = values().iterator();

                // Find least recently used and not busy connection in cache
                while ( iterator.hasNext() ) {
                    Connection c = (Connection) iterator.next();
                    if ( !c.isBusy() && c.getTimeStamp() < lru ) {
                        toClose = c;
                        lru = c.getTimeStamp();
                    }
                }

                if ( toClose == null ) {
                    return false;
                }

                try {
                    if (orb.transportDebugFlag) {
                        dprint(".reclaim: closing: " + toClose);
                    }
                    toClose.close();
                } catch (Exception ex) {
                    // REVISIT - log
                }
            }

            if (orb.transportDebugFlag) {
                dprint(".reclaim: connections reclaimed ("
                        + (numberOfConnections - numberOfConnections()) + ")");
            }
        }

        // XXX is necessary to do a GC to reclaim
        // closed network connections ??
        // java.lang.System.gc();

        return true;
    } finally {
        if (orb.transportDebugFlag) {
            dprint(".reclaim<-: " + numberOfConnections());
        }
    }
}
 
Example 5
Source File: CorbaConnectionCacheBase.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Discarding least recently used Connections that are not busy
 *
 * This method must be synchronized since one WorkerThread could
 * be reclaming connections inside the synchronized backingStore
 * block and a second WorkerThread (or a SelectorThread) could have
 * already executed the if (numberOfConnections <= .... ). As a
 * result the second thread would also attempt to reclaim connections.
 *
 * If connection reclamation becomes a performance issue, the connection
 * reclamation could make its own task and consequently executed in
 * a separate thread.
 * Currently, the accept & reclaim are done in the same thread, WorkerThread
 * by default. It could be changed such that the SelectorThread would do
 * it for SocketChannels and WorkerThreads for Sockets by updating the
 * ParserTable.
 */
synchronized public boolean reclaim()
{
    try {
        long numberOfConnections = numberOfConnections();

        if (orb.transportDebugFlag) {
            dprint(".reclaim->: " + numberOfConnections
                    + " ("
                    + orb.getORBData().getHighWaterMark()
                    + "/"
                    + orb.getORBData().getLowWaterMark()
                    + "/"
                    + orb.getORBData().getNumberToReclaim()
                    + ")");
        }

        if (numberOfConnections <= orb.getORBData().getHighWaterMark() ||
            numberOfConnections < orb.getORBData().getLowWaterMark()) {
            return false;
        }

        Object backingStore = backingStore();
        synchronized (backingStore) {

             // REVISIT - A less expensive alternative connection reclaiming
             //           algorithm could be investigated.

            for (int i=0; i < orb.getORBData().getNumberToReclaim(); i++) {
                Connection toClose = null;
                long lru = java.lang.Long.MAX_VALUE;
                Iterator iterator = values().iterator();

                // Find least recently used and not busy connection in cache
                while ( iterator.hasNext() ) {
                    Connection c = (Connection) iterator.next();
                    if ( !c.isBusy() && c.getTimeStamp() < lru ) {
                        toClose = c;
                        lru = c.getTimeStamp();
                    }
                }

                if ( toClose == null ) {
                    return false;
                }

                try {
                    if (orb.transportDebugFlag) {
                        dprint(".reclaim: closing: " + toClose);
                    }
                    toClose.close();
                } catch (Exception ex) {
                    // REVISIT - log
                }
            }

            if (orb.transportDebugFlag) {
                dprint(".reclaim: connections reclaimed ("
                        + (numberOfConnections - numberOfConnections()) + ")");
            }
        }

        // XXX is necessary to do a GC to reclaim
        // closed network connections ??
        // java.lang.System.gc();

        return true;
    } finally {
        if (orb.transportDebugFlag) {
            dprint(".reclaim<-: " + numberOfConnections());
        }
    }
}
 
Example 6
Source File: CorbaConnectionCacheBase.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Discarding least recently used Connections that are not busy
 *
 * This method must be synchronized since one WorkerThread could
 * be reclaming connections inside the synchronized backingStore
 * block and a second WorkerThread (or a SelectorThread) could have
 * already executed the if (numberOfConnections <= .... ). As a
 * result the second thread would also attempt to reclaim connections.
 *
 * If connection reclamation becomes a performance issue, the connection
 * reclamation could make its own task and consequently executed in
 * a separate thread.
 * Currently, the accept & reclaim are done in the same thread, WorkerThread
 * by default. It could be changed such that the SelectorThread would do
 * it for SocketChannels and WorkerThreads for Sockets by updating the
 * ParserTable.
 */
synchronized public boolean reclaim()
{
    try {
        long numberOfConnections = numberOfConnections();

        if (orb.transportDebugFlag) {
            dprint(".reclaim->: " + numberOfConnections
                    + " ("
                    + orb.getORBData().getHighWaterMark()
                    + "/"
                    + orb.getORBData().getLowWaterMark()
                    + "/"
                    + orb.getORBData().getNumberToReclaim()
                    + ")");
        }

        if (numberOfConnections <= orb.getORBData().getHighWaterMark() ||
            numberOfConnections < orb.getORBData().getLowWaterMark()) {
            return false;
        }

        Object backingStore = backingStore();
        synchronized (backingStore) {

             // REVISIT - A less expensive alternative connection reclaiming
             //           algorithm could be investigated.

            for (int i=0; i < orb.getORBData().getNumberToReclaim(); i++) {
                Connection toClose = null;
                long lru = java.lang.Long.MAX_VALUE;
                Iterator iterator = values().iterator();

                // Find least recently used and not busy connection in cache
                while ( iterator.hasNext() ) {
                    Connection c = (Connection) iterator.next();
                    if ( !c.isBusy() && c.getTimeStamp() < lru ) {
                        toClose = c;
                        lru = c.getTimeStamp();
                    }
                }

                if ( toClose == null ) {
                    return false;
                }

                try {
                    if (orb.transportDebugFlag) {
                        dprint(".reclaim: closing: " + toClose);
                    }
                    toClose.close();
                } catch (Exception ex) {
                    // REVISIT - log
                }
            }

            if (orb.transportDebugFlag) {
                dprint(".reclaim: connections reclaimed ("
                        + (numberOfConnections - numberOfConnections()) + ")");
            }
        }

        // XXX is necessary to do a GC to reclaim
        // closed network connections ??
        // java.lang.System.gc();

        return true;
    } finally {
        if (orb.transportDebugFlag) {
            dprint(".reclaim<-: " + numberOfConnections());
        }
    }
}
 
Example 7
Source File: CorbaConnectionCacheBase.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Discarding least recently used Connections that are not busy
 *
 * This method must be synchronized since one WorkerThread could
 * be reclaming connections inside the synchronized backingStore
 * block and a second WorkerThread (or a SelectorThread) could have
 * already executed the if (numberOfConnections {@literal <=} .... ). As a
 * result the second thread would also attempt to reclaim connections.
 *
 * If connection reclamation becomes a performance issue, the connection
 * reclamation could make its own task and consequently executed in
 * a separate thread.
 * Currently, the accept {@literal &} reclaim are done in the same thread, WorkerThread
 * by default. It could be changed such that the SelectorThread would do
 * it for SocketChannels and WorkerThreads for Sockets by updating the
 * ParserTable.
 */
synchronized public boolean reclaim()
{
    try {
        long numberOfConnections = numberOfConnections();

        if (orb.transportDebugFlag) {
            dprint(".reclaim->: " + numberOfConnections
                    + " ("
                    + orb.getORBData().getHighWaterMark()
                    + "/"
                    + orb.getORBData().getLowWaterMark()
                    + "/"
                    + orb.getORBData().getNumberToReclaim()
                    + ")");
        }

        if (numberOfConnections <= orb.getORBData().getHighWaterMark() ||
            numberOfConnections < orb.getORBData().getLowWaterMark()) {
            return false;
        }

        Object backingStore = backingStore();
        synchronized (backingStore) {

             // REVISIT - A less expensive alternative connection reclaiming
             //           algorithm could be investigated.

            for (int i=0; i < orb.getORBData().getNumberToReclaim(); i++) {
                Connection toClose = null;
                long lru = java.lang.Long.MAX_VALUE;
                Iterator iterator = values().iterator();

                // Find least recently used and not busy connection in cache
                while ( iterator.hasNext() ) {
                    Connection c = (Connection) iterator.next();
                    if ( !c.isBusy() && c.getTimeStamp() < lru ) {
                        toClose = c;
                        lru = c.getTimeStamp();
                    }
                }

                if ( toClose == null ) {
                    return false;
                }

                try {
                    if (orb.transportDebugFlag) {
                        dprint(".reclaim: closing: " + toClose);
                    }
                    toClose.close();
                } catch (Exception ex) {
                    // REVISIT - log
                }
            }

            if (orb.transportDebugFlag) {
                dprint(".reclaim: connections reclaimed ("
                        + (numberOfConnections - numberOfConnections()) + ")");
            }
        }

        // XXX is necessary to do a GC to reclaim
        // closed network connections ??
        // java.lang.System.gc();

        return true;
    } finally {
        if (orb.transportDebugFlag) {
            dprint(".reclaim<-: " + numberOfConnections());
        }
    }
}
 
Example 8
Source File: CorbaConnectionCacheBase.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Discarding least recently used Connections that are not busy
 *
 * This method must be synchronized since one WorkerThread could
 * be reclaming connections inside the synchronized backingStore
 * block and a second WorkerThread (or a SelectorThread) could have
 * already executed the if (numberOfConnections <= .... ). As a
 * result the second thread would also attempt to reclaim connections.
 *
 * If connection reclamation becomes a performance issue, the connection
 * reclamation could make its own task and consequently executed in
 * a separate thread.
 * Currently, the accept & reclaim are done in the same thread, WorkerThread
 * by default. It could be changed such that the SelectorThread would do
 * it for SocketChannels and WorkerThreads for Sockets by updating the
 * ParserTable.
 */
synchronized public boolean reclaim()
{
    try {
        long numberOfConnections = numberOfConnections();

        if (orb.transportDebugFlag) {
            dprint(".reclaim->: " + numberOfConnections
                    + " ("
                    + orb.getORBData().getHighWaterMark()
                    + "/"
                    + orb.getORBData().getLowWaterMark()
                    + "/"
                    + orb.getORBData().getNumberToReclaim()
                    + ")");
        }

        if (numberOfConnections <= orb.getORBData().getHighWaterMark() ||
            numberOfConnections < orb.getORBData().getLowWaterMark()) {
            return false;
        }

        Object backingStore = backingStore();
        synchronized (backingStore) {

             // REVISIT - A less expensive alternative connection reclaiming
             //           algorithm could be investigated.

            for (int i=0; i < orb.getORBData().getNumberToReclaim(); i++) {
                Connection toClose = null;
                long lru = java.lang.Long.MAX_VALUE;
                Iterator iterator = values().iterator();

                // Find least recently used and not busy connection in cache
                while ( iterator.hasNext() ) {
                    Connection c = (Connection) iterator.next();
                    if ( !c.isBusy() && c.getTimeStamp() < lru ) {
                        toClose = c;
                        lru = c.getTimeStamp();
                    }
                }

                if ( toClose == null ) {
                    return false;
                }

                try {
                    if (orb.transportDebugFlag) {
                        dprint(".reclaim: closing: " + toClose);
                    }
                    toClose.close();
                } catch (Exception ex) {
                    // REVISIT - log
                }
            }

            if (orb.transportDebugFlag) {
                dprint(".reclaim: connections reclaimed ("
                        + (numberOfConnections - numberOfConnections()) + ")");
            }
        }

        // XXX is necessary to do a GC to reclaim
        // closed network connections ??
        // java.lang.System.gc();

        return true;
    } finally {
        if (orb.transportDebugFlag) {
            dprint(".reclaim<-: " + numberOfConnections());
        }
    }
}
 
Example 9
Source File: CorbaConnectionCacheBase.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Discarding least recently used Connections that are not busy
 *
 * This method must be synchronized since one WorkerThread could
 * be reclaming connections inside the synchronized backingStore
 * block and a second WorkerThread (or a SelectorThread) could have
 * already executed the if (numberOfConnections <= .... ). As a
 * result the second thread would also attempt to reclaim connections.
 *
 * If connection reclamation becomes a performance issue, the connection
 * reclamation could make its own task and consequently executed in
 * a separate thread.
 * Currently, the accept & reclaim are done in the same thread, WorkerThread
 * by default. It could be changed such that the SelectorThread would do
 * it for SocketChannels and WorkerThreads for Sockets by updating the
 * ParserTable.
 */
synchronized public boolean reclaim()
{
    try {
        long numberOfConnections = numberOfConnections();

        if (orb.transportDebugFlag) {
            dprint(".reclaim->: " + numberOfConnections
                    + " ("
                    + orb.getORBData().getHighWaterMark()
                    + "/"
                    + orb.getORBData().getLowWaterMark()
                    + "/"
                    + orb.getORBData().getNumberToReclaim()
                    + ")");
        }

        if (numberOfConnections <= orb.getORBData().getHighWaterMark() ||
            numberOfConnections < orb.getORBData().getLowWaterMark()) {
            return false;
        }

        Object backingStore = backingStore();
        synchronized (backingStore) {

             // REVISIT - A less expensive alternative connection reclaiming
             //           algorithm could be investigated.

            for (int i=0; i < orb.getORBData().getNumberToReclaim(); i++) {
                Connection toClose = null;
                long lru = java.lang.Long.MAX_VALUE;
                Iterator iterator = values().iterator();

                // Find least recently used and not busy connection in cache
                while ( iterator.hasNext() ) {
                    Connection c = (Connection) iterator.next();
                    if ( !c.isBusy() && c.getTimeStamp() < lru ) {
                        toClose = c;
                        lru = c.getTimeStamp();
                    }
                }

                if ( toClose == null ) {
                    return false;
                }

                try {
                    if (orb.transportDebugFlag) {
                        dprint(".reclaim: closing: " + toClose);
                    }
                    toClose.close();
                } catch (Exception ex) {
                    // REVISIT - log
                }
            }

            if (orb.transportDebugFlag) {
                dprint(".reclaim: connections reclaimed ("
                        + (numberOfConnections - numberOfConnections()) + ")");
            }
        }

        // XXX is necessary to do a GC to reclaim
        // closed network connections ??
        // java.lang.System.gc();

        return true;
    } finally {
        if (orb.transportDebugFlag) {
            dprint(".reclaim<-: " + numberOfConnections());
        }
    }
}
 
Example 10
Source File: CorbaConnectionCacheBase.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Discarding least recently used Connections that are not busy
 *
 * This method must be synchronized since one WorkerThread could
 * be reclaming connections inside the synchronized backingStore
 * block and a second WorkerThread (or a SelectorThread) could have
 * already executed the if (numberOfConnections <= .... ). As a
 * result the second thread would also attempt to reclaim connections.
 *
 * If connection reclamation becomes a performance issue, the connection
 * reclamation could make its own task and consequently executed in
 * a separate thread.
 * Currently, the accept & reclaim are done in the same thread, WorkerThread
 * by default. It could be changed such that the SelectorThread would do
 * it for SocketChannels and WorkerThreads for Sockets by updating the
 * ParserTable.
 */
synchronized public boolean reclaim()
{
    try {
        long numberOfConnections = numberOfConnections();

        if (orb.transportDebugFlag) {
            dprint(".reclaim->: " + numberOfConnections
                    + " ("
                    + orb.getORBData().getHighWaterMark()
                    + "/"
                    + orb.getORBData().getLowWaterMark()
                    + "/"
                    + orb.getORBData().getNumberToReclaim()
                    + ")");
        }

        if (numberOfConnections <= orb.getORBData().getHighWaterMark() ||
            numberOfConnections < orb.getORBData().getLowWaterMark()) {
            return false;
        }

        Object backingStore = backingStore();
        synchronized (backingStore) {

             // REVISIT - A less expensive alternative connection reclaiming
             //           algorithm could be investigated.

            for (int i=0; i < orb.getORBData().getNumberToReclaim(); i++) {
                Connection toClose = null;
                long lru = java.lang.Long.MAX_VALUE;
                Iterator iterator = values().iterator();

                // Find least recently used and not busy connection in cache
                while ( iterator.hasNext() ) {
                    Connection c = (Connection) iterator.next();
                    if ( !c.isBusy() && c.getTimeStamp() < lru ) {
                        toClose = c;
                        lru = c.getTimeStamp();
                    }
                }

                if ( toClose == null ) {
                    return false;
                }

                try {
                    if (orb.transportDebugFlag) {
                        dprint(".reclaim: closing: " + toClose);
                    }
                    toClose.close();
                } catch (Exception ex) {
                    // REVISIT - log
                }
            }

            if (orb.transportDebugFlag) {
                dprint(".reclaim: connections reclaimed ("
                        + (numberOfConnections - numberOfConnections()) + ")");
            }
        }

        // XXX is necessary to do a GC to reclaim
        // closed network connections ??
        // java.lang.System.gc();

        return true;
    } finally {
        if (orb.transportDebugFlag) {
            dprint(".reclaim<-: " + numberOfConnections());
        }
    }
}