39
39
import java .lang .reflect .InvocationTargetException ;
40
40
41
41
import jp .ossc .nimbus .beans .*;
42
+ import jp .ossc .nimbus .beans .dataset .*;
42
43
import jp .ossc .nimbus .core .*;
43
44
import jp .ossc .nimbus .daemon .*;
44
45
import jp .ossc .nimbus .service .publish .*;
@@ -1648,8 +1649,8 @@ public boolean locks(Set keys, boolean ifAcquireable, boolean ifExist, long time
1648
1649
return result ;
1649
1650
}
1650
1651
currentTimeout = isNoTimeout ? currentTimeout : timeout - (System .currentTimeMillis () - start );
1651
- if (!isNoTimeout && timeout <= 0 ){
1652
- throw new SharedContextTimeoutException ();
1652
+ if (!isNoTimeout && currentTimeout <= 0 ){
1653
+ throw new SharedContextTimeoutException ("keys=" + keys . size () + ", timeout=" + timeout + ", processTime=" + ( System . currentTimeMillis () - start ) );
1653
1654
}
1654
1655
}else {
1655
1656
if (ifAcquireable ){
@@ -1736,6 +1737,9 @@ public boolean locks(Set keys, boolean ifAcquireable, boolean ifExist, long time
1736
1737
throw new NoConnectServerException ("Main server is not found." );
1737
1738
}
1738
1739
currentTimeout = isNoTimeout ? currentTimeout : timeout - (System .currentTimeMillis () - start );
1740
+ if (!isNoTimeout && currentTimeout <= 0 ){
1741
+ throw new SharedContextTimeoutException ();
1742
+ }
1739
1743
keyItr = keys .iterator ();
1740
1744
while (keyItr .hasNext ()){
1741
1745
Object key = keyItr .next ();
@@ -1760,7 +1764,7 @@ public boolean locks(Set keys, boolean ifAcquireable, boolean ifExist, long time
1760
1764
}
1761
1765
}
1762
1766
currentTimeout = isNoTimeout ? currentTimeout : timeout - (System .currentTimeMillis () - start );
1763
- if (!isNoTimeout && timeout <= 0 ){
1767
+ if (!isNoTimeout && currentTimeout <= 0 ){
1764
1768
throw new SharedContextTimeoutException ();
1765
1769
}
1766
1770
}
@@ -2173,12 +2177,10 @@ public Object getUpdateTemplate(Object key, long timeout) throws SharedContextSe
2173
2177
2174
2178
public Object getUpdateTemplate (Object key , long timeout , boolean withTransaction ) throws SharedContextSendException , SharedContextTimeoutException {
2175
2179
Object value = null ;
2176
- final boolean isNoTimeout = timeout <= 0 ;
2177
- long currentTimeout = timeout ;
2178
2180
if (withTransaction && sharedContextTransactionManager != null ){
2179
2181
SharedContextTransactionManager .SharedContextTransaction transaction = sharedContextTransactionManager .getTransaction ();
2180
2182
if (transaction != null && (transaction .getState () == SharedContextTransactionManager .SharedContextTransaction .STATE_BEGIN )){
2181
- return transaction .getUpdateTemplate (this , key , currentTimeout );
2183
+ return transaction .getUpdateTemplate (this , key , timeout );
2182
2184
}
2183
2185
}
2184
2186
if (isClient ){
@@ -2195,7 +2197,7 @@ public Object getUpdateTemplate(Object key, long timeout, boolean withTransactio
2195
2197
clientSubject ,
2196
2198
key == null ? null : key .toString (),
2197
2199
1 ,
2198
- currentTimeout
2200
+ timeout
2199
2201
);
2200
2202
Object result = responses [0 ].getObject ();
2201
2203
responses [0 ].recycle ();
@@ -2254,40 +2256,33 @@ protected void update(Object key, SharedContextValueDifference diff, long timeou
2254
2256
}
2255
2257
}
2256
2258
}
2259
+ final boolean isNoTimeout = timeout <= 0 ;
2260
+ long currentTimeout = timeout ;
2257
2261
try {
2258
2262
Object oldValue = null ;
2259
- long startTime = System .currentTimeMillis ();
2263
+ long start = System .currentTimeMillis ();
2260
2264
if (!updateLock .acquireForUse (timeout )){
2261
2265
throw new SharedContextTimeoutException ();
2262
2266
}
2263
- if (timeout > 0 ){
2264
- timeout -= (System .currentTimeMillis () - startTime );
2265
- if (timeout <= 0 ){
2266
- throw new SharedContextTimeoutException ();
2267
- }
2268
- startTime = System .currentTimeMillis ();
2267
+ currentTimeout = isNoTimeout ? currentTimeout : timeout - (System .currentTimeMillis () - start );
2268
+ if (!isNoTimeout && currentTimeout <= 0 ){
2269
+ throw new SharedContextTimeoutException ();
2269
2270
}
2270
- if (!referLock .acquireForUse (timeout )){
2271
+ if (!referLock .acquireForUse (currentTimeout )){
2271
2272
throw new SharedContextTimeoutException ();
2272
2273
}
2273
- if (timeout > 0 ){
2274
- timeout -= (System .currentTimeMillis () - startTime );
2275
- if (timeout <= 0 ){
2276
- throw new SharedContextTimeoutException ();
2277
- }
2278
- startTime = System .currentTimeMillis ();
2274
+ currentTimeout = isNoTimeout ? currentTimeout : timeout - (System .currentTimeMillis () - start );
2275
+ if (!isNoTimeout && currentTimeout <= 0 ){
2276
+ throw new SharedContextTimeoutException ();
2279
2277
}
2280
2278
Object current = getRawLocal (key );
2281
2279
Object currentValue = unwrapCachedReference (current , false , false );
2282
2280
if (currentValue == null ){
2283
2281
if (isClient && isEnabledIndexOnClient ){
2284
- currentValue = get (key , timeout );
2285
- if (timeout > 0 ){
2286
- timeout -= (System .currentTimeMillis () - startTime );
2287
- if (timeout <= 0 ){
2288
- throw new SharedContextTimeoutException ();
2289
- }
2290
- startTime = System .currentTimeMillis ();
2282
+ currentValue = get (key , currentTimeout );
2283
+ currentTimeout = isNoTimeout ? currentTimeout : timeout - (System .currentTimeMillis () - start );
2284
+ if (!isNoTimeout && currentTimeout <= 0 ){
2285
+ throw new SharedContextTimeoutException ();
2291
2286
}
2292
2287
}
2293
2288
if (currentValue == null
@@ -2319,7 +2314,7 @@ protected void update(Object key, SharedContextValueDifference diff, long timeou
2319
2314
isClient ? clientSubject : subject ,
2320
2315
key == null ? null : key .toString (),
2321
2316
0 ,
2322
- timeout
2317
+ currentTimeout
2323
2318
);
2324
2319
for (int i = 0 ; i < responses .length ; i ++){
2325
2320
Object ret = responses [i ].getObject ();
@@ -3177,12 +3172,12 @@ public Object get(Object key, long timeout, boolean withTransaction) throws Shar
3177
3172
}
3178
3173
}
3179
3174
try {
3180
- long startTime = System .currentTimeMillis ();
3175
+ long start = System .currentTimeMillis ();
3181
3176
if (!referLock .acquireForUse (currentTimeout )){
3182
3177
throw new SharedContextTimeoutException ();
3183
3178
}
3184
3179
if (!isNoTimeout && currentTimeout <= 0 ){
3185
- currentTimeout -= (System .currentTimeMillis () - startTime );
3180
+ currentTimeout = isNoTimeout ? currentTimeout : timeout - (System .currentTimeMillis () - start );
3186
3181
if (currentTimeout <= 0 ){
3187
3182
throw new SharedContextTimeoutException ();
3188
3183
}
@@ -3207,11 +3202,10 @@ public Object get(Object key, long timeout, boolean withTransaction) throws Shar
3207
3202
}
3208
3203
if (lock != null ){
3209
3204
lock .init ();
3210
- final long start = System .currentTimeMillis ();
3211
3205
if (!lock .waitLock (currentTimeout )){
3212
3206
throw new SharedContextTimeoutException ();
3213
3207
}
3214
- currentTimeout = isNoTimeout ? timeout : currentTimeout - (System .currentTimeMillis () - start );
3208
+ currentTimeout = isNoTimeout ? timeout : timeout - (System .currentTimeMillis () - start );
3215
3209
if (!isNoTimeout && currentTimeout <= 0 ){
3216
3210
throw new SharedContextTimeoutException ();
3217
3211
}
@@ -5954,13 +5948,14 @@ public synchronized void callback(Lock lock, boolean notify){
5954
5948
}else {
5955
5949
message .setDestinationIds (receiveClients );
5956
5950
long currentTimeout = isNoTimeout ? timeout : timeout - (System .currentTimeMillis () - startTime );
5957
- if (!isNoTimeout && timeout <= 0 ){
5951
+ if (!isNoTimeout && currentTimeout <= 0 ){
5958
5952
Message response = createResponseMessage (responseSubject , responseKey , new SharedContextTimeoutException ());
5959
5953
try {
5960
5954
serverConnection .response (sourceId , sequence , response );
5961
5955
}catch (MessageSendException e ){
5962
5956
getLogger ().write ("SCS__00006" , new Object []{isClient ? clientSubject : subject , response }, e );
5963
5957
}
5958
+ return ;
5964
5959
}
5965
5960
message .setObject (
5966
5961
new SharedContextEvent (
@@ -6704,6 +6699,76 @@ public Set getResultSet(){
6704
6699
return resultSet == null ? indexManager .keySet () : resultSet ;
6705
6700
}
6706
6701
6702
+ public Set getResultValueSet () throws SharedContextSendException , SharedContextTimeoutException {
6703
+ return getResultValueSet (defaultTimeout );
6704
+ }
6705
+
6706
+ public Set getResultValueSet (long timeout ) throws SharedContextSendException , SharedContextTimeoutException {
6707
+ Set keySet = getResultSet ();
6708
+ if (keySet == null ){
6709
+ return null ;
6710
+ }
6711
+ Set resultValueSet = new LinkedHashSet ();
6712
+ final long start = System .currentTimeMillis ();
6713
+ long currentTimeout = timeout ;
6714
+ Iterator keys = keySet .iterator ();
6715
+ while (keys .hasNext ()){
6716
+ if (timeout > 0 ){
6717
+ currentTimeout = timeout - (System .currentTimeMillis () - start );
6718
+ if (currentTimeout <= 0 ){
6719
+ throw new SharedContextTimeoutException ();
6720
+ }
6721
+ }
6722
+ resultValueSet .add (get (keys .next (), currentTimeout ));
6723
+ }
6724
+
6725
+ return resultValueSet ;
6726
+ }
6727
+
6728
+ public List getResultValueList () throws SharedContextSendException , SharedContextTimeoutException {
6729
+ return getResultValueList (defaultTimeout );
6730
+ }
6731
+
6732
+ public List getResultValueList (long timeout ) throws SharedContextSendException , SharedContextTimeoutException {
6733
+ Set keySet = getResultSet ();
6734
+ if (keySet == null ){
6735
+ return null ;
6736
+ }
6737
+ List resultValueList = new ArrayList ();
6738
+ final long start = System .currentTimeMillis ();
6739
+ long currentTimeout = timeout ;
6740
+ Iterator keys = keySet .iterator ();
6741
+ while (keys .hasNext ()){
6742
+ if (timeout > 0 ){
6743
+ currentTimeout = timeout - (System .currentTimeMillis () - start );
6744
+ if (currentTimeout <= 0 ){
6745
+ throw new SharedContextTimeoutException ();
6746
+ }
6747
+ }
6748
+ resultValueList .add (get (keys .next (), currentTimeout ));
6749
+ }
6750
+
6751
+ return resultValueList ;
6752
+ }
6753
+
6754
+ public List getResultValueList (long timeout , String [] propNames ) throws SharedContextSendException , SharedContextTimeoutException {
6755
+ return getResultValueList (timeout , propNames , null );
6756
+ }
6757
+
6758
+ public List getResultValueList (long timeout , String [] propNames , boolean [] isAsc ) throws SharedContextSendException , SharedContextTimeoutException {
6759
+ List resultValueList = getResultValueList (timeout );
6760
+ if (resultValueList == null || resultValueList .size () == 0 ){
6761
+ return resultValueList ;
6762
+ }
6763
+ Object template = resultValueList .get (0 );
6764
+ if (template instanceof Record ){
6765
+ RecordList .sort (resultValueList , propNames , isAsc );
6766
+ }else {
6767
+ Collections .sort (resultValueList , new BeanTableView .BeanComparator (template .getClass (), propNames , isAsc ));
6768
+ }
6769
+ return resultValueList ;
6770
+ }
6771
+
6707
6772
public SharedContextView and (){
6708
6773
operator = OPERATOR_AND ;
6709
6774
return this ;
0 commit comments