Class DefaultSVNRepositoryPool
- java.lang.Object
-
- org.tmatesoft.svn.core.wc.DefaultSVNRepositoryPool
-
- All Implemented Interfaces:
ISVNConnectionListener
,ISVNSession
,ISVNRepositoryPool
public class DefaultSVNRepositoryPool extends java.lang.Object implements ISVNRepositoryPool, ISVNSession, ISVNConnectionListener
The DefaultSVNRepositoryPool class is a default implementation of the ISVNRepositoryPool interface.It creates SVNRepository objects that may be stored in a common pool and reused later. The objects common pool may be shared by different threads, but each thread can retrieve only those objects, that have been created within that thread. So, DefaultSVNRepositoryPool is thread-safe. An objects pool may be global during runtime, or it may be private - one separate pool per one DefaultSVNRepositoryPool object. Also there's a possibility to have a DefaultSVNRepositoryPool object with the pool feature disabled (SVNRepository objects instantiated by such a creator are never cached).
DefaultSVNRepositoryPool caches one SVNRepository object per one url protocol (per one thread), that is the number of protocols used equals to the number of objects cached per one thread (if all objects are created as reusable).
Also DefaultSVNRepositoryPool is able to create SVNRepository objects that use a single socket connection (i.e. don't close a connection after every repository access operation but reuse a single one).
- Since:
- 1.2
- Version:
- 1.3
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DefaultSVNRepositoryPool.DaemonThreadFactory
private class
DefaultSVNRepositoryPool.TimeoutTask
-
Field Summary
Fields Modifier and Type Field Description private static long
DEFAULT_IDLE_TIMEOUT
static int
INSTANCE_POOL
Deprecated.private ISVNAuthenticationManager
myAuthManager
private ISVNCanceller
myCanceller
private ISVNDebugLog
myDebugLog
private java.util.Map<SVNRepository,java.lang.Long>
myInactiveRepositories
private boolean
myIsKeepConnection
private java.util.Map<java.lang.String,SVNRepository>
myPool
private java.util.concurrent.ScheduledFuture<?>
myScheduledTimeoutTask
private java.io.File
mySpoolLocation
private long
myTimeout
private java.util.concurrent.ScheduledExecutorService
myTimer
private ISVNTunnelProvider
myTunnelProvider
static int
NO_POOL
Deprecated.private static int
ourInstanceCount
private static java.util.concurrent.ScheduledExecutorService
ourTimer
static int
RUNTIME_POOL
Deprecated.-
Fields inherited from interface org.tmatesoft.svn.core.io.ISVNSession
DEFAULT, KEEP_ALIVE
-
-
Constructor Summary
Constructors Constructor Description DefaultSVNRepositoryPool(ISVNAuthenticationManager authManager, ISVNTunnelProvider tunnelProvider)
Constructs a DefaultSVNRepositoryPool instance that representsRUNTIME_POOL
objects pool.DefaultSVNRepositoryPool(ISVNAuthenticationManager authManager, ISVNTunnelProvider tunnelProvider, boolean keepConnections, int poolMode)
Deprecated.DefaultSVNRepositoryPool(ISVNAuthenticationManager authManager, ISVNTunnelProvider tunnelProvider, long timeout, boolean keepConnection)
Constructs a DefaultSVNRepositoryPool instance that representsRUNTIME_POOL
objects pool.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connectionClosed(SVNRepository repository)
Places the specifiedrepository
into the pool of inactiveSVNRepository
objects.void
connectionOpened(SVNRepository repository)
Removes the specifiedrepository
object from the pool of inactiveSVNRepository
objects held by this object.private java.util.concurrent.ScheduledExecutorService
createExecutor()
SVNRepository
createRepository(SVNURL url, boolean mayReuse)
Creates a new SVNRepository driver object.void
dispose()
Disposes this pool.java.lang.String
getCommitMessage(SVNRepository repository, long revision)
Returns null.private java.util.Map<java.lang.String,SVNRepository>
getPool()
java.io.File
getSpoolLocation()
private long
getTimeout()
boolean
hasCommitMessage(SVNRepository repository, long revision)
Returns false.boolean
keepConnection(SVNRepository repository)
Says if the given SVNRepository driver object should keep a connection opened.void
saveCommitMessage(SVNRepository repository, long revision, java.lang.String message)
Does nothing.void
setAuthenticationManager(ISVNAuthenticationManager authManager)
Sets the given authentication instance to this pool and to allSVNRepository
objects stored in this pool.void
setCanceller(ISVNCanceller canceller)
Sets a canceller to be used in allSVNRepository
objects produced by this pool.void
setDebugLog(ISVNDebugLog log)
Sets a debug logger to be used in allSVNRepository
objects produced by this pool.private void
setOptionalSpoolLocation(SVNRepository repos, ISVNTunnelProvider options)
void
setSpoolLocation(java.io.File location)
void
shutdownConnections(boolean shutdownAll)
Closes connections of cached SVNRepository objects.private void
shutdownInactiveRepositories(long currentTime)
static void
shutdownTimer()
Stops the daemon thread that checks whether there are anySVNRepository
objects expired.
-
-
-
Field Detail
-
RUNTIME_POOL
public static final int RUNTIME_POOL
Deprecated.Defines a common shared objects pool. All objects that will be created by different threads will be stored in this common pool.- See Also:
- Constant Field Values
-
INSTANCE_POOL
public static final int INSTANCE_POOL
Deprecated.Defines a private pool. All objects that will be created by different threads will be stored only within this pool object. This allows to have more than one separate pools.- See Also:
- Constant Field Values
-
NO_POOL
public static final int NO_POOL
Deprecated.Defines a without-pool configuration. Objects that are created by this DefaultSVNRepositoryPool object are not cached, the pool feature is disabled.- See Also:
- Constant Field Values
-
DEFAULT_IDLE_TIMEOUT
private static final long DEFAULT_IDLE_TIMEOUT
- See Also:
- Constant Field Values
-
ourTimer
private static volatile java.util.concurrent.ScheduledExecutorService ourTimer
-
ourInstanceCount
private static volatile int ourInstanceCount
-
myAuthManager
private ISVNAuthenticationManager myAuthManager
-
myTunnelProvider
private ISVNTunnelProvider myTunnelProvider
-
myDebugLog
private ISVNDebugLog myDebugLog
-
myCanceller
private ISVNCanceller myCanceller
-
myPool
private java.util.Map<java.lang.String,SVNRepository> myPool
-
myTimeout
private long myTimeout
-
myInactiveRepositories
private java.util.Map<SVNRepository,java.lang.Long> myInactiveRepositories
-
myTimer
private java.util.concurrent.ScheduledExecutorService myTimer
-
myIsKeepConnection
private boolean myIsKeepConnection
-
myScheduledTimeoutTask
private java.util.concurrent.ScheduledFuture<?> myScheduledTimeoutTask
-
mySpoolLocation
private java.io.File mySpoolLocation
-
-
Constructor Detail
-
DefaultSVNRepositoryPool
public DefaultSVNRepositoryPool(ISVNAuthenticationManager authManager, ISVNTunnelProvider tunnelProvider)
Constructs a DefaultSVNRepositoryPool instance that representsRUNTIME_POOL
objects pool. SVNRepository objects created by this instance will use a single socket connection. This constructor is identical toDefaultSVNRepositoryPool(authManager, tunnelProvider, DEFAULT_IDLE_TIMEOUT, true)
.- Parameters:
authManager
- an authentication drivertunnelProvider
- a tunnel provider
-
DefaultSVNRepositoryPool
public DefaultSVNRepositoryPool(ISVNAuthenticationManager authManager, ISVNTunnelProvider tunnelProvider, long timeout, boolean keepConnection)
Constructs a DefaultSVNRepositoryPool instance that representsRUNTIME_POOL
objects pool. SVNRepository objects created by this instance will use a single socket connection.- Parameters:
authManager
- an authentication drivertunnelProvider
- a tunnel providertimeout
- inactivity timeout after which open connections should be closedkeepConnection
- whether to keep connection open
-
DefaultSVNRepositoryPool
public DefaultSVNRepositoryPool(ISVNAuthenticationManager authManager, ISVNTunnelProvider tunnelProvider, boolean keepConnections, int poolMode)
Deprecated.Constructs a DefaultSVNRepositoryPool instance.- Parameters:
authManager
- an authentication drivertunnelProvider
- a tunnel providerkeepConnections
- if true then SVNRepository objects will keep a single connection for accessing a repository, if false - open a new connection per each repository access operationpoolMode
- a mode of this object represented by one of the constant fields of DefaultSVNRepositoryPool
-
-
Method Detail
-
createExecutor
private java.util.concurrent.ScheduledExecutorService createExecutor()
-
createRepository
public SVNRepository createRepository(SVNURL url, boolean mayReuse) throws SVNException
Creates a new SVNRepository driver object. ifmayReuse
is true and the mode of this DefaultSVNRepositoryPool object is notNO_POOL
then first tries to find the SVNRepository object in the pool for the given protocol. If the object is not found, creates a new one for that protocol, caches it in the pool and returns back.NOTE: be careful when simultaneously using several SVNRepository drivers for the same protocol - since there can be only one driver object in the pool per a protocol, creating two objects for the same protocol with
mayReuse
set to true, actually returns the same single object stored in the thread pool.- Specified by:
createRepository
in interfaceISVNRepositoryPool
- Parameters:
url
- a repository location for which a driver is to be createdmayReuse
- if true then SVNRepository object is reusable- Returns:
- a new SVNRepository driver object
- Throws:
SVNException
- See Also:
SVNRepository
-
setSpoolLocation
public void setSpoolLocation(java.io.File location)
-
getSpoolLocation
public java.io.File getSpoolLocation()
-
setOptionalSpoolLocation
private void setOptionalSpoolLocation(SVNRepository repos, ISVNTunnelProvider options)
-
setAuthenticationManager
public void setAuthenticationManager(ISVNAuthenticationManager authManager)
Sets the given authentication instance to this pool and to allSVNRepository
objects stored in this pool.- Specified by:
setAuthenticationManager
in interfaceISVNRepositoryPool
- Parameters:
authManager
- authentication manager instance
-
keepConnection
public boolean keepConnection(SVNRepository repository)
Says if the given SVNRepository driver object should keep a connection opened. If this object was created withkeepConnections
set to true and ifrepository
is not created for the "svn+ssh" protocol (since for this protocol there's no extra need to keep a connection opened - it remains opened), this method returns true.- Specified by:
keepConnection
in interfaceISVNSession
- Parameters:
repository
- an SVNRepository driver- Returns:
- true if the driver should keep a connection
-
shutdownConnections
public void shutdownConnections(boolean shutdownAll)
Closes connections of cached SVNRepository objects.Actually, calls the
dispose()
routine.- Specified by:
shutdownConnections
in interfaceISVNRepositoryPool
- Parameters:
shutdownAll
- if true - closes connections of all the cached objects, otherwise only connections of those cached objects which owner threads have already disposed- See Also:
SVNRepository
-
dispose
public void dispose()
Disposes this pool. Clears all inactiveSVNRepository
objects from this pool.- Specified by:
dispose
in interfaceISVNRepositoryPool
- Since:
- 1.2.0
-
shutdownTimer
public static void shutdownTimer()
Stops the daemon thread that checks whether there are anySVNRepository
objects expired.- Since:
- 1.1.5
- See Also:
connectionClosed(SVNRepository)
-
saveCommitMessage
public void saveCommitMessage(SVNRepository repository, long revision, java.lang.String message)
Does nothing.- Specified by:
saveCommitMessage
in interfaceISVNSession
- Parameters:
repository
- an SVNRepository driver (to distinguish that repository for which this message is actual)revision
- a revision numbermessage
- the commit message forrevision
- See Also:
ISVNSession.getCommitMessage(SVNRepository, long)
-
getCommitMessage
public java.lang.String getCommitMessage(SVNRepository repository, long revision)
Returns null.- Specified by:
getCommitMessage
in interfaceISVNSession
- Parameters:
repository
- an SVNRepository driver (to distinguish that repository for which a commit message is requested)revision
- a revision number- Returns:
- the commit message for
revision
- See Also:
ISVNSession.saveCommitMessage(SVNRepository, long, String)
-
hasCommitMessage
public boolean hasCommitMessage(SVNRepository repository, long revision)
Returns false.- Specified by:
hasCommitMessage
in interfaceISVNSession
- Parameters:
repository
- an SVNRepository driver (to distinguish that repository for which a commit message is requested)revision
- a revision number- Returns:
- true if the cache has got a message for the given repository and revision, false otherwise
-
connectionClosed
public void connectionClosed(SVNRepository repository)
Places the specifiedrepository
into the pool of inactiveSVNRepository
objects. If this pool keeps connections open (refer to thekeepConnection
parameter of theconstructor
), then eachSVNRepository
object which is passed to this method (what means it finished the operation), must be reused in a period of time not greater than the timeout value. The timeout value is either equal to the value passed to theconstructor
, or it defaults to 60 seconds if no valid timeout value was provided. Otherwise the repository object will beclosed
. Timeout checking occurs one time in 10 seconds. This behavior - closing repository objects after timeout - can be changed by switching off the timer thread viashutdownTimer()
.- Specified by:
connectionClosed
in interfaceISVNConnectionListener
- Parameters:
repository
- repository access object- Since:
- 1.1.4
-
connectionOpened
public void connectionOpened(SVNRepository repository)
Removes the specifiedrepository
object from the pool of inactiveSVNRepository
objects held by this object. This method is synchronized.- Specified by:
connectionOpened
in interfaceISVNConnectionListener
- Parameters:
repository
- repository access object to remove from the pool- Since:
- 1.1.4
-
setCanceller
public void setCanceller(ISVNCanceller canceller)
Sets a canceller to be used in allSVNRepository
objects produced by this pool.- Specified by:
setCanceller
in interfaceISVNRepositoryPool
- Parameters:
canceller
- caller's canceller- Since:
- 1.1.4
-
setDebugLog
public void setDebugLog(ISVNDebugLog log)
Sets a debug logger to be used in allSVNRepository
objects produced by this pool.- Specified by:
setDebugLog
in interfaceISVNRepositoryPool
- Parameters:
log
- debug logger- Since:
- 1.1.4
-
getTimeout
private long getTimeout()
-
getPool
private java.util.Map<java.lang.String,SVNRepository> getPool()
-
shutdownInactiveRepositories
private void shutdownInactiveRepositories(long currentTime)
-
-