Skip to content

Commit 2a56f18

Browse files
merged mongo-java-driver master
2 parents 4c8d2fe + 029d3e5 commit 2a56f18

6 files changed

Lines changed: 62 additions & 39 deletions

File tree

build.xml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version='1.0'?>
22
<project name="MongoDB Java Driver" default="compile" basedir=".">
33

4-
<property name="version" value="2.0rc3"/>
4+
<property name="version" value="2.0rc4"/>
55
<property name="targetdir" location="target"/>
66
<property name="testdir" location="${targetdir}/test"/>
77

@@ -158,15 +158,31 @@
158158
debug="on" >
159159
<classpath refid="classpath"/>
160160
</javac>
161-
161+
162162
<java classname="QuickTour" >
163163
<classpath refid="classpath"/>
164164
</java>
165165

166166
<java classname="QuickTourAdmin" >
167167
<classpath refid="classpath"/>
168168
</java>
169-
169+
170+
</target>
171+
172+
<target name="publish">
173+
<exec dir="." executable="python">
174+
<arg value="mavenPush.py"/>
175+
<arg value="${version}"/>
176+
<arg value="/ebs/maven/"/>
177+
</exec>
178+
</target>
179+
180+
<target name="publish-local">
181+
<exec dir="." executable="python">
182+
<arg value="mavenPush.py"/>
183+
<arg value="${version}"/>
184+
<arg value="~/.m2/repository/"/>
185+
</exec>
170186
</target>
171187

172188
</project>

mavenPush.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88
import subprocess
99

1010
if len( sys.argv ) == 1:
11-
raise Exception( "need version number for now" )
11+
print "Usage: mavenPush.py VERSION [PUBDIR]"
12+
print "VERSION - version you want to publish"
13+
print "PUBDIR - directory to publish to. default = /ebs/maven/"
14+
sys.exit()
1215

1316
version = sys.argv[1]
1417

15-
root = "/ebs/maven/"
18+
if len( sys.argv ) > 2:
19+
root = os.path.expanduser( sys.argv[2] )
20+
else:
21+
root = "/ebs/maven/"
1622

1723
p = subprocess.Popen( [ "/usr/bin/ant" , "clean" ] , stdout=subprocess.PIPE ).communicate()
1824
p = subprocess.Popen( [ "/usr/bin/ant" , "alljars" ] , stdout=subprocess.PIPE ).communicate()

src/main/com/mongodb/DBApiLayer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.bson.types.*;
2626

2727
import com.mongodb.util.*;
28+
2829
/** Database API
2930
* This cannot be directly instantiated, but the functions are available
3031
* through instances of Mongo.

src/main/com/mongodb/DBPortPool.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,21 @@ void close(){
6969
// ----
7070

7171
public static class NoMoreConnection extends MongoInternalException {
72-
NoMoreConnection(){
73-
super( "No more DB Connections" );
72+
NoMoreConnection( String msg ){
73+
super( msg );
7474
}
7575
}
7676

77-
public static class ConnectionWaitTimeOut extends MongoInternalException {
78-
ConnectionWaitTimeOut(int timeout) {
79-
super("Connection wait timeout after " + timeout + " ms");
80-
}
77+
public static class SemaphoresOut extends NoMoreConnection {
78+
SemaphoresOut(){
79+
super( "Out of semaphores to get db connection" );
80+
}
81+
}
82+
83+
public static class ConnectionWaitTimeOut extends NoMoreConnection {
84+
ConnectionWaitTimeOut(int timeout) {
85+
super("Connection wait timeout after " + timeout + " ms");
86+
}
8187
}
8288

8389
// ----
@@ -96,7 +102,7 @@ protected long memSize( DBPort p ){
96102
public DBPort get(){
97103
DBPort port = null;
98104
if ( ! _waitingSem.tryAcquire() )
99-
throw new NoMoreConnection();
105+
throw new SemaphoresOut();
100106

101107
try {
102108
port = get( _options.maxWaitTime );

src/main/com/mongodb/DBTCPConnector.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,10 @@ public Response call( DB db , DBCollection coll , OutMessage m , int retries )
176176

177177
port.checkAuth( db );
178178

179+
Response res = null;
179180
try {
180-
Response res = port.call( m , coll );
181+
res = port.call( m , coll );
181182
mp.done( port );
182-
ServerError err = res.getError();
183-
184-
if ( err != null && err.isNotMasterError() ){
185-
_pickCurrent();
186-
if ( retries <= 0 ){
187-
throw new MongoException( "not talking to master and retries used up" );
188-
}
189-
190-
return call( db , coll , m , retries -1 );
191-
}
192-
193-
return res;
194183
}
195184
catch ( IOException ioe ){
196185
mp.error( ioe );
@@ -199,13 +188,22 @@ public Response call( DB db , DBCollection coll , OutMessage m , int retries )
199188
}
200189
throw new MongoException.Network( "can't call something" , ioe );
201190
}
202-
catch ( MongoException me ){
203-
throw me;
204-
}
205191
catch ( RuntimeException re ){
206192
mp.error( re );
207193
throw re;
208194
}
195+
196+
ServerError err = res.getError();
197+
198+
if ( err != null && err.isNotMasterError() ){
199+
_pickCurrent();
200+
if ( retries <= 0 ){
201+
throw new MongoException( "not talking to master and retries used up" );
202+
}
203+
return call( db , coll , m , retries -1 );
204+
}
205+
206+
return res;
209207
}
210208

211209
public ServerAddress getAddress(){

src/main/com/mongodb/Mongo.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.net.*;
2222
import java.util.*;
23+
import java.util.concurrent.*;
2324

2425
/**
2526
* A database connection with internal pooling.
@@ -165,16 +166,11 @@ public DB getDB( String dbname ){
165166
if ( db != null )
166167
return db;
167168

168-
synchronized ( _dbs ){
169-
db = _dbs.get( dbname );
170-
if ( db != null )
171-
return db;
172-
173-
db = new DBApiLayer( dbname , _connector );
174-
175-
_dbs.put( dbname , db );
176-
return db;
177-
}
169+
db = new DBApiLayer( dbname , _connector );
170+
DB temp = _dbs.putIfAbsent( dbname , db );
171+
if ( temp != null )
172+
return temp;
173+
return db;
178174
}
179175

180176
public List<String> getDatabaseNames()
@@ -250,5 +246,5 @@ public void close(){
250246
final List<ServerAddress> _addrs;
251247
final MongoOptions _options;
252248
final DBTCPConnector _connector;
253-
final Map<String,DB> _dbs = new HashMap<String,DB>();
249+
final ConcurrentMap<String,DB> _dbs = new ConcurrentHashMap<String,DB>();
254250
}

0 commit comments

Comments
 (0)