Skip to content

Commit 724365b

Browse files
committed
#58 - Rename methods with deprecation: getName() -> name(), getStatus() -> status() etc
1 parent f855c1c commit 724365b

7 files changed

Lines changed: 81 additions & 60 deletions

File tree

ebean-datasource-api/src/main/java/io/ebean/datasource/DataSourcePool.java

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ public interface DataSourcePool extends DataSource {
1111
/**
1212
* Return the dataSource name.
1313
*/
14-
String getName();
14+
String name();
15+
16+
/**
17+
* Deprecated migate to name().
18+
*/
19+
@Deprecated
20+
default String getName() {
21+
return name();
22+
}
1523

1624
/**
1725
* Return the current size of the pool. This includes both busy and idle connections.
@@ -30,6 +38,13 @@ public interface DataSourcePool extends DataSource {
3038
*/
3139
boolean isOnline();
3240

41+
/**
42+
* Returns false when the dataSource is down.
43+
* <p>
44+
* Effectively the same as (synonym for) {@link #isOnline()}.
45+
*/
46+
boolean isDataSourceUp();
47+
3348
/**
3449
* Bring the DataSource online ensuring min connections and start heart beat checking.
3550
*/
@@ -44,7 +59,7 @@ public interface DataSourcePool extends DataSource {
4459
* Shutdown the pool.
4560
* <p>
4661
* This is functionally the same as {@link #offline()} but generally we expect to only
47-
* shutdown the pool once where as we can expect to making many calls to offline() and
62+
* shutdown the pool once whereas we can expect to make many calls to offline() and
4863
* online().
4964
*/
5065
void shutdown();
@@ -57,37 +72,46 @@ public interface DataSourcePool extends DataSource {
5772
* <p>
5873
* If you pass reset = true then the counters are reset.
5974
*/
60-
PoolStatus getStatus(boolean reset);
75+
PoolStatus status(boolean reset);
6176

6277
/**
63-
* Returns false when the dataSource is down.
64-
* <p>
65-
* Effectively the same as (synonym for) {@link #isOnline()}.
78+
* Deprecated migrate to status().
6679
*/
67-
boolean isDataSourceUp();
80+
@Deprecated
81+
default PoolStatus getStatus(boolean reset) {
82+
return status(reset);
83+
}
6884

6985
/**
7086
* Returns the reason, why the dataSource is down.
7187
*/
72-
SQLException getDataSourceDownReason();
88+
SQLException dataSourceDownReason();
89+
90+
/**
91+
* Deprecated migrate to dataSourceDownReason().
92+
*/
93+
@Deprecated
94+
default SQLException getDataSourceDownReason() {
95+
return dataSourceDownReason();
96+
}
7397

7498
/**
7599
* Set a new maximum size. The pool should respect this new maximum
76-
* immediately and not require a restart. You may want to increase the
100+
* immediately and not require a restart. We may want to increase the
77101
* maxConnections if the pool gets large and hits the warning level.
78102
*/
79103
void setMaxSize(int max);
80104

81105
/**
82-
* Set a new maximum size. The pool should respect this new maximum immediately
83-
* and not require a restart. You may want to increase the maxConnections if the
84-
* pool gets large and hits the warning and or alert levels.
106+
* Set a new maximum size. The pool should respect this new warning level immediately
107+
* and not require a restart. We may want to increase the maxConnections if the
108+
* pool gets large and hits the warning levels.
85109
*/
86110
void setWarningSize(int warningSize);
87111

88112
/**
89113
* Return the warning size. When the pool hits this size it can send a
90-
* notify message to an administrator.
114+
* warning message to an administrator.
91115
*/
92116
int getWarningSize();
93117

ebean-datasource/src/main/java/io/ebean/datasource/pool/ConnectionPool.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public <T> T unwrap(Class<T> arg0) throws SQLException {
273273
* Return the dataSource name.
274274
*/
275275
@Override
276-
public String getName() {
276+
public String name() {
277277
return name;
278278
}
279279

@@ -306,16 +306,8 @@ int getMaxStackTraceSize() {
306306
return maxStackTraceSize;
307307
}
308308

309-
/**
310-
* Returns false when the dataSource is down.
311-
*/
312-
@Override
313-
public boolean isDataSourceUp() {
314-
return dataSourceUp.get();
315-
}
316-
317309
@Override
318-
public SQLException getDataSourceDownReason() {
310+
public SQLException dataSourceDownReason() {
319311
return dataSourceDownReason;
320312
}
321313

@@ -776,6 +768,11 @@ public boolean isOnline() {
776768
return dataSourceUp.get();
777769
}
778770

771+
@Override
772+
public boolean isDataSourceUp() {
773+
return dataSourceUp.get();
774+
}
775+
779776
private void startHeartBeatIfStopped() {
780777
heartbeatLock.lock();
781778
try {
@@ -931,7 +928,7 @@ public void setPstmtCacheSize(int pstmtCacheSize) {
931928
* </p>
932929
*/
933930
@Override
934-
public PoolStatus getStatus(boolean reset) {
931+
public PoolStatus status(boolean reset) {
935932
return queue.getStatus(reset);
936933
}
937934

ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ final class PooledConnection extends ConnectionDelegator {
115115
super(connection);
116116
this.pool = pool;
117117
this.connection = connection;
118-
this.name = pool.getName() + uniqueId;
118+
this.name = pool.name() + uniqueId;
119119
this.pstmtCache = new PstmtCache(pool.getPstmtCacheSize());
120120
this.maxStackTrace = pool.getMaxStackTraceSize();
121121
this.creationTime = System.currentTimeMillis();

ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnectionQueue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ final class PooledConnectionQueue {
6464

6565
PooledConnectionQueue(ConnectionPool pool) {
6666
this.pool = pool;
67-
this.name = pool.getName();
67+
this.name = pool.name();
6868
this.minSize = pool.getMinSize();
6969
this.maxSize = pool.getMaxSize();
7070
this.warningSize = pool.getWarningSize();

ebean-datasource/src/test/java/io/ebean/datasource/pool/ConnectionPoolOfflineTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,43 +41,43 @@ public void testOffline() throws InterruptedException, SQLException {
4141
log.info("pool created ");
4242

4343
waitFor(() -> {
44-
assertEquals(0, pool.getStatus(false).getFree());
45-
assertEquals(0, pool.getStatus(false).getBusy());
44+
assertEquals(0, pool.status(false).getFree());
45+
assertEquals(0, pool.status(false).getBusy());
4646
assertThat(pool.size()).isEqualTo(0);
4747
});
48-
48+
4949
pool.online();
5050
log.info("pool online");
5151
assertThat(pool.isOnline()).isTrue();
52-
assertEquals(2, pool.getStatus(false).getFree());
53-
assertEquals(0, pool.getStatus(false).getBusy());
52+
assertEquals(2, pool.status(false).getFree());
53+
assertEquals(0, pool.status(false).getBusy());
5454
assertThat(pool.size()).isEqualTo(2);
5555

5656
pool.offline();
5757
log.info("pool offline");
5858
waitFor(() -> {
5959
assertThat(pool.isOnline()).isFalse();
60-
assertEquals(0, pool.getStatus(false).getFree());
61-
assertEquals(0, pool.getStatus(false).getBusy());
60+
assertEquals(0, pool.status(false).getFree());
61+
assertEquals(0, pool.status(false).getBusy());
6262
assertThat(pool.size()).isEqualTo(0);
6363
});
6464

6565
pool.online();
6666
log.info("pool online");
67-
67+
6868
waitFor(() -> {
6969
assertThat(pool.isOnline()).isTrue();
70-
assertEquals(2, pool.getStatus(false).getFree());
71-
assertEquals(0, pool.getStatus(false).getBusy());
70+
assertEquals(2, pool.status(false).getFree());
71+
assertEquals(0, pool.status(false).getBusy());
7272
assertThat(pool.size()).isEqualTo(2);
7373
});
74-
74+
7575
pool.shutdown();
7676

7777
waitFor(() -> {
7878
assertThat(pool.isOnline()).isFalse();
79-
assertEquals(0, pool.getStatus(false).getFree());
80-
assertEquals(0, pool.getStatus(false).getBusy());
79+
assertEquals(0, pool.status(false).getFree());
80+
assertEquals(0, pool.status(false).getBusy());
8181
assertThat(pool.size()).isEqualTo(0);
8282
});
8383
}
@@ -126,19 +126,19 @@ public void offline_whenBusy_allowed() throws SQLException, InterruptedException
126126

127127
Thread.sleep(200);
128128
System.out.println("-- taking pool offline (with a busy connection)");
129-
assertEquals(1, pool.getStatus(false).getBusy());
129+
assertEquals(1, pool.status(false).getBusy());
130130
assertThat(pool.size()).isEqualTo(2);
131131

132132
pool.offline();
133-
assertEquals(0, pool.getStatus(false).getFree());
134-
assertEquals(1, pool.getStatus(false).getBusy()); // still 1 busy connection
133+
assertEquals(0, pool.status(false).getFree());
134+
assertEquals(1, pool.status(false).getBusy()); // still 1 busy connection
135135
assertThat(pool.size()).isEqualTo(1);
136136

137137
// wait to let busy connection finish and close
138138
waitFor(() -> {
139139
// all done now
140-
assertEquals(0, pool.getStatus(false).getFree());
141-
assertEquals(0, pool.getStatus(false).getBusy());
140+
assertEquals(0, pool.status(false).getFree());
141+
assertEquals(0, pool.status(false).getBusy());
142142
assertThat(pool.size()).isEqualTo(0);
143143
});
144144
}

ebean-datasource/src/test/java/io/ebean/datasource/pool/ConnectionPoolTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,28 @@ public void getConnection_expect_poolGrowsAboveMin() throws SQLException {
4242
Connection con1 = pool.getConnection();
4343
Connection con2 = pool.getConnection();
4444

45-
assertThat(pool.getStatus(false).getBusy()).isEqualTo(2);
46-
assertThat(pool.getStatus(false).getFree()).isEqualTo(0);
45+
assertThat(pool.status(false).getBusy()).isEqualTo(2);
46+
assertThat(pool.status(false).getFree()).isEqualTo(0);
4747
assertThat(pool.size()).isEqualTo(2);
4848

4949
Connection con3 = pool.getConnection();
50-
assertThat(pool.getStatus(false).getBusy()).isEqualTo(3);
51-
assertThat(pool.getStatus(false).getFree()).isEqualTo(0);
50+
assertThat(pool.status(false).getBusy()).isEqualTo(3);
51+
assertThat(pool.status(false).getFree()).isEqualTo(0);
5252
assertThat(pool.size()).isEqualTo(3);
5353

5454
con2.close();
55-
assertThat(pool.getStatus(false).getBusy()).isEqualTo(2);
56-
assertThat(pool.getStatus(false).getFree()).isEqualTo(1);
55+
assertThat(pool.status(false).getBusy()).isEqualTo(2);
56+
assertThat(pool.status(false).getFree()).isEqualTo(1);
5757
assertThat(pool.size()).isEqualTo(3);
5858

5959
con3.close();
60-
assertThat(pool.getStatus(false).getBusy()).isEqualTo(1);
61-
assertThat(pool.getStatus(false).getFree()).isEqualTo(2);
60+
assertThat(pool.status(false).getBusy()).isEqualTo(1);
61+
assertThat(pool.status(false).getFree()).isEqualTo(2);
6262
assertThat(pool.size()).isEqualTo(3);
6363

6464
con1.close();
65-
assertThat(pool.getStatus(false).getBusy()).isEqualTo(0);
66-
assertThat(pool.getStatus(false).getFree()).isEqualTo(3);
65+
assertThat(pool.status(false).getBusy()).isEqualTo(0);
66+
assertThat(pool.status(false).getFree()).isEqualTo(3);
6767
assertThat(pool.size()).isEqualTo(3);
6868
}
6969

ebean-datasource/src/test/java/io/ebean/datasource/pool/ConnectionPoolTrimIdleTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public void test() throws SQLException, InterruptedException {
4545
con3.close();
4646
con4.close();
4747
assertThat(pool.size()).isEqualTo(4);
48-
assertThat(pool.getStatus(false).getFree()).isEqualTo(4);
48+
assertThat(pool.status(false).getFree()).isEqualTo(4);
4949

5050
waitFor(() -> {
51-
assertThat(pool.getStatus(false).getFree()).isEqualTo(1);
51+
assertThat(pool.status(false).getFree()).isEqualTo(1);
5252
assertThat(pool.size()).isEqualTo(1);
5353
});
5454
} finally {
@@ -71,28 +71,28 @@ public void test_withDecreasingActivity_expect_trimToActivityLevel() throws SQLE
7171
}
7272

7373
// start at 10 connections
74-
assertThat(pool.getStatus(false).getFree()).isEqualTo(10);
74+
assertThat(pool.status(false).getFree()).isEqualTo(10);
7575
assertThat(pool.size()).isEqualTo(10);
7676

7777
// keep 4 connections busy
7878
Timer timer0 = createTimer(pool, 4);
7979

8080
waitFor(() -> {
81-
assertThat(pool.getStatus(false).getFree()).isEqualTo(4);
81+
assertThat(pool.status(false).getFree()).isEqualTo(4);
8282
});
8383
timer0.cancel();
8484

8585
// keep 2 connections busy
8686
Timer timer1 = createTimer(pool, 2);
8787

8888
waitFor(() -> {
89-
assertThat(pool.getStatus(false).getFree()).isEqualTo(2);
89+
assertThat(pool.status(false).getFree()).isEqualTo(2);
9090
});
9191
timer1.cancel();
9292

9393
// Go Idle
9494
waitFor(() -> {
95-
assertThat(pool.getStatus(false).getFree()).isEqualTo(1);
95+
assertThat(pool.status(false).getFree()).isEqualTo(1);
9696
assertThat(pool.size()).isEqualTo(1);
9797
});
9898
} finally {

0 commit comments

Comments
 (0)