You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ja...@apache.org on 2008/08/12 07:06:44 UTC
svn commit: r685041 -
/maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/deploy/DeploymentTarget.java
Author: janb
Date: Mon Aug 11 22:06:43 2008
New Revision: 685041
URL: http://svn.apache.org/viewvc?rev=685041&view=rev
Log:
Fix thread race on deployment.
Modified:
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/deploy/DeploymentTarget.java
Modified: maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/deploy/DeploymentTarget.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/deploy/DeploymentTarget.java?rev=685041&r1=685040&r2=685041&view=diff
==============================================================================
--- maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/deploy/DeploymentTarget.java (original)
+++ maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/deploy/DeploymentTarget.java Mon Aug 11 22:06:43 2008
@@ -51,7 +51,7 @@
protected String _remoteJettyUrl;
protected Set<StreamObserver> _observers = new HashSet<StreamObserver>();
protected List<StreamVerifier> _verifiers = new ArrayList<StreamVerifier>();
- protected int _index = -1;
+ protected int _checkSumFilesDeployed = -1;
public abstract void onComplete();
@@ -156,6 +156,10 @@
_checksumState = new TargetState();
}
+ public Binding getBinding()
+ {
+ return _binding;
+ }
public void deploy()
{
@@ -164,6 +168,7 @@
private synchronized void updateState( Throwable t )
{
+
if ( t != null && _exception == null )
{
_exception = ( t instanceof HttpClientException ? (HttpClientException) t : new HttpClientException( _binding, t ) );
@@ -180,14 +185,12 @@
{
deployLocalFile();
}
-
//Upload the checksums
- if ( _targetState.isReady() && (++_index) < _verifiers.size() )
+ else if ( _targetState.isReady() && (_verifiers.size()>0) && (_checkSumFilesDeployed < (_verifiers.size() -1)) )
{
- deployChecksumFile();
+ deployNextChecksumFile();
}
-
- if ( _targetState.isReady() && _checksumState.isReady() )
+ else if ( _targetState.isReady() && _checksumState.isReady() )
{
onComplete();
}
@@ -196,10 +199,11 @@
private void deployLocalFile()
{
- FilePutExchange exchange = new FilePutExchange( _batchId, _binding, _binding.getLocalFile(), _observers, _httpClient )
+ FilePutExchange fileExchange = new FilePutExchange( _batchId, _binding, _binding.getLocalFile(), _observers, _httpClient )
{
public void onFileComplete( String url, File localFile )
{
+
DeploymentTarget.this._remoteJettyUrl = getRemoteJettyUrl();
_targetState.ready();
updateState( null );
@@ -207,21 +211,22 @@
public void onFileError( String url, Exception e )
{
+
DeploymentTarget.this._remoteJettyUrl = getRemoteJettyUrl();
_targetState.ready( e );
updateState( e );
}
};
_targetState.requested();
- exchange.send();
+ fileExchange.send();
}
- private void deployChecksumFile()
+ private void deployNextChecksumFile()
{
Binding binding = _binding;
File file = null;
- StreamVerifier v = _verifiers.get(_index);
+ StreamVerifier v = _verifiers.get(++_checkSumFilesDeployed);
//No local checksum file, so make a temporary one using the checksum we
//calculated as we uploaded the file
@@ -250,26 +255,26 @@
//upload the checksum file
Set<StreamObserver> emptySet = Collections.emptySet();
- FilePutExchange exchange = new FilePutExchange( _batchId, binding, file, emptySet, _httpClient )
+ FilePutExchange checksumExchange = new FilePutExchange( _batchId, binding, file, emptySet, _httpClient )
{
public void onFileComplete( String url, File localFile )
- {
+ {
DeploymentTarget.this._remoteJettyUrl = getRemoteJettyUrl();
- if (_index == (_verifiers.size() - 1))
+ if (_checkSumFilesDeployed == (_verifiers.size() - 1))
_checksumState.ready();
updateState( null );
}
public void onFileError( String url, Exception e )
- {
+ {
DeploymentTarget.this._remoteJettyUrl = getRemoteJettyUrl();
- if (_index == (_verifiers.size() - 1))
+ if (_checkSumFilesDeployed == (_verifiers.size() - 1))
_checksumState.ready( e );
updateState( e );
}
};
_checksumState.requested();
- exchange.send();
+ checksumExchange.send();
}
public boolean isRemoteJetty()
@@ -307,4 +312,5 @@
{
return "DeploymentTarget:" + _binding.getRemoteResource() + ":" + _targetState + ":" + _checksumState + ":" + isComplete();
}
+
}