rem
stringlengths
0
477k
add
stringlengths
0
313k
context
stringlengths
6
599k
_cache = new Hashtable();
_cache = new ScalableMap(1001);
public void init(Broker b, Properties config) throws InitException { _log = b.getLog("resource"); _cache = new Hashtable(); }
} if (!serviceFactory.isEnabled()) { throw new ServiceRegistrationException(serviceName, new IllegalServiceStateException("A disabled non-restartable service factory can not be registered", serviceName));
public void registerService(ServiceName serviceName, ServiceFactory serviceFactory, ClassLoader classLoader) throws ServiceAlreadyExistsException, ServiceRegistrationException { assert serviceName != null : "serviceName is null"; assert serviceFactory != null : "serviceFactory is null"; assert classLoader != null : "classLoader is null"; if (!running.get()) { throw new IllegalStateException("Kernel is stopped"); } FutureTask registrationTask = null; // // This loop will continue until we put our registrationTask in the serviceManagers map. If at any point, // we discover that there is already a service registered under the specified service name, we will throw // a ServiceAlreadyExistsException exiting this method. // while (registrationTask == null) { Future existingRegistration; synchronized (serviceManagers) { existingRegistration = (Future) serviceManagers.get(serviceName); // if we do not have an existing registration or the existing registration task is complete // we can create the new registration task; otherwise we need to wait for the existing registration to // finish out side of the synchronized lock on serviceManagers. if (existingRegistration == null || existingRegistration.isDone()) { // if we have a valid existing registration, throw a ServiceAlreadyExistsException if (existingRegistration != null) { try { boolean alreadyRegistered = (existingRegistration.get() != null); if (alreadyRegistered) { throw new ServiceAlreadyExistsException(serviceName); } } catch (InterruptedException e) { throw new KernelOperationInterruptedException(e, serviceName, "registerService"); } catch (ExecutionException e) { // the previous registration threw an exception.. we can continure as normal } } // we are ready to register our serviceManager existingRegistration = null; registrationTask = new FutureTask(new RegisterServiceManager(serviceName, serviceFactory, classLoader)); serviceManagers.put(serviceName, registrationTask); } } // If there is an unfinished exiting registration task, wait until it is done executing if (existingRegistration != null) { try { existingRegistration.get(); // we don't throw an error here because we want to check in the synchronized block that this // future is still registered in the serviceManagers map } catch (InterruptedException e) { throw new KernelOperationInterruptedException(e, serviceName, "registerService"); } catch (ExecutionException e) { // good } } } // run our registration task and check the results registrationTask.run(); try { // if initialization completed successfully, this method will not throw an exception registrationTask.get(); } catch (InterruptedException e) { throw new KernelOperationInterruptedException(e, serviceName, "registerService"); } catch (ExecutionException e) { throw new ServiceRegistrationException(serviceName, e.getCause()); } }
context.put ("OWNM", new ObjectWithNullMethod());
public void stuffContext (Context context) throws Exception { context.setEvaluationExceptionHandler ( new DefaultEvaluationExceptionHandler ()); context.put ("TestObject", new TestObject()); context.put ("NullTestObject", new NullTestObject()); context.put ("NullObject", null); }
if (br != null) { try { br.close(); } catch (IOException e2) { } }
private String generateHtmlizedJavaSource(SourceFileData sourceFileData) { File sourceFile = null; try { sourceFile = finder.getFileForSource(sourceFileData.getName()); } catch (IOException e) { return "<p>Unable to locate " + sourceFileData.getName() + ". Have you specified the source directory?</p>"; } BufferedReader br = null; try { br = new BufferedReader(new FileReader(sourceFile)); } catch (FileNotFoundException e) { if (br != null) { try { br.close(); } catch (IOException e2) { } } return "<p>Unable to open " + sourceFile.getAbsolutePath() + "</p>"; } StringBuffer ret = new StringBuffer(); ret .append("<table cellspacing=\"0\" cellpadding=\"0\" class=\"src\">\n"); try { String lineStr; JavaToHtml javaToHtml = new JavaToHtml(); int lineNumber = 1; while ((lineStr = br.readLine()) != null) { ret.append("<tr>"); if (sourceFileData.isValidSourceLineNumber(lineNumber)) { long numberOfHits = sourceFileData.getHitCount(lineNumber); ret.append(" <td class=\"numLineCover\">&nbsp;" + lineNumber + "</td>"); if (numberOfHits > 0) { ret.append(" <td class=\"nbHitsCovered\">&nbsp;" + numberOfHits + "</td>"); ret .append(" <td class=\"src\"><pre class=\"src\">&nbsp;" + javaToHtml.process(lineStr) + "</pre></td>"); } else { ret.append(" <td class=\"nbHitsUncovered\">&nbsp;" + numberOfHits + "</td>"); ret .append(" <td class=\"src\"><pre class=\"src\"><span class=\"srcUncovered\">&nbsp;" + javaToHtml.process(lineStr) + "</span></pre></td>"); } } else { ret.append(" <td class=\"numLine\">&nbsp;" + lineNumber + "</td>"); ret.append(" <td class=\"nbHits\">&nbsp;</td>\n"); ret.append(" <td class=\"src\"><pre class=\"src\">&nbsp;" + javaToHtml.process(lineStr) + "</pre></td>"); } ret.append("</tr>\n"); lineNumber++; } } catch (IOException e) { ret.append("<tr><td>Error reading from file " + sourceFile.getAbsolutePath() + ": " + e.getLocalizedMessage() + "</td></tr>\n"); } finally { try { br.close(); } catch (IOException e) { } } ret.append("</table>\n"); return ret.toString(); }
if ((jjbitVec0[i2] & l2) != 0L && kind > 32)
if (jjCanMove_0(hiByte, i1, i2, l1, l2) && kind > 32)
private final int jjMoveNfa_0(int startState, int curPos){ int[] nextStates; int startsAt = 0; jjnewStateCnt = 48; int i = 1; jjstateSet[0] = startState; int j, kind = 0x7fffffff; for (;;) { if (++jjround == 0x7fffffff) ReInitRounds(); if (curChar < 64) { long l = 1L << curChar; MatchLoop: do { switch(jjstateSet[--i]) { case 10: case 9: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 15) kind = 15; jjCheckNAdd(9); break; case 7: if ((0xfc00ffffffffffffL & l) != 0L) { if (kind > 32) kind = 32; } else if ((0x3ff000000000000L & l) != 0L) jjCheckNAddStates(0, 3); if ((0x3ff000000000000L & l) != 0L) { if (kind > 23) kind = 23; jjCheckNAddStates(4, 8); } else if ((0x100000200L & l) != 0L) { if (kind > 27) kind = 27; } else if (curChar == 13) jjAddStates(9, 10); else if (curChar == 10) { if (kind > 25) kind = 25; jjCheckNAddTwoStates(42, 44); } if (curChar == 32) jjstateSet[jjnewStateCnt++] = 14; break; case 49: case 1: jjCheckNAddStates(11, 13); break; case 48: jjCheckNAddStates(11, 13); break; case 3: jjCheckNAddStates(14, 16); break; case 6: jjCheckNAddStates(17, 20); break; case 11: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 16) kind = 16; jjstateSet[jjnewStateCnt++] = 11; break; case 13: if (curChar == 32) jjstateSet[jjnewStateCnt++] = 14; break; case 14: if (curChar == 32 && kind > 26) kind = 26; break; case 15: if ((0x100000200L & l) != 0L && kind > 27) kind = 27; break; case 16: if ((0xfc00ffffffffffffL & l) != 0L && kind > 32) kind = 32; break; case 17: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 23) kind = 23; jjCheckNAddStates(4, 8); break; case 18: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddTwoStates(18, 19); break; case 20: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddTwoStates(20, 21); break; case 21: if (curChar == 46) jjstateSet[jjnewStateCnt++] = 22; break; case 22: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 19) kind = 19; jjCheckNAdd(23); break; case 23: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 19) kind = 19; jjCheckNAddStates(21, 23); break; case 24: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddTwoStates(24, 25); break; case 25: if (curChar == 58) jjstateSet[jjnewStateCnt++] = 26; break; case 26: if ((0xa7ffe06000000000L & l) == 0L) break; if (kind > 20) kind = 20; jjCheckNAddStates(24, 26); break; case 27: if ((0xa7ffe06000000000L & l) == 0L) break; if (kind > 20) kind = 20; jjCheckNAdd(27); break; case 28: if ((0xa7ffe06000000000L & l) != 0L) jjCheckNAddTwoStates(28, 29); break; case 29: if (curChar == 40) jjCheckNAdd(30); break; case 30: if ((0xfffffdffffffdbffL & l) != 0L) jjCheckNAddTwoStates(30, 31); break; case 31: if (curChar == 41 && kind > 20) kind = 20; break; case 32: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 23) kind = 23; jjCheckNAdd(32); break; case 33: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddStates(0, 3); break; case 34: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddTwoStates(34, 35); break; case 35: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 21) kind = 21; jjCheckNAddTwoStates(35, 36); break; case 36: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 21) kind = 21; jjCheckNAddStates(27, 29); break; case 37: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddTwoStates(37, 38); break; case 38: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddStates(30, 32); break; case 40: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddStates(33, 36); break; case 41: if (curChar != 10) break; if (kind > 25) kind = 25; jjCheckNAddTwoStates(42, 44); break; case 42: case 43: if (curChar == 10 && kind > 24) kind = 24; break; case 44: if (curChar == 13) jjstateSet[jjnewStateCnt++] = 43; break; case 45: if (curChar == 13) jjAddStates(9, 10); break; case 46: if (curChar == 10) jjCheckNAddTwoStates(42, 44); break; case 47: if (curChar == 10 && kind > 25) kind = 25; break; default : break; } } while(i != startsAt); } else if (curChar < 128) { long l = 1L << (curChar & 077); MatchLoop: do { switch(jjstateSet[--i]) { case 10: if ((0x7fffffe07fffffeL & l) != 0L) { if (kind > 15) kind = 15; jjCheckNAdd(9); } else if (curChar == 64) { if (kind > 16) kind = 16; jjCheckNAdd(11); } break; case 7: if ((0x7fffffe07fffffeL & l) != 0L) { if (kind > 23) kind = 23; jjCheckNAddStates(4, 8); } else if ((0xf8000001f8000001L & l) != 0L) { if (kind > 32) kind = 32; } if ((0x7fffffeL & l) != 0L) jjCheckNAddStates(0, 3); else if (curChar == 94) jjstateSet[jjnewStateCnt++] = 10; else if (curChar == 91) jjstateSet[jjnewStateCnt++] = 0; if (curChar == 94) jjCheckNAdd(9); break; case 49: if ((0xffffffffdfffffffL & l) != 0L) jjCheckNAddStates(11, 13); else if (curChar == 93) jjstateSet[jjnewStateCnt++] = 4; if (curChar == 93) jjstateSet[jjnewStateCnt++] = 3; break; case 48: if ((0xffffffffdfffffffL & l) != 0L) jjCheckNAddStates(11, 13); else if (curChar == 93) jjstateSet[jjnewStateCnt++] = 3; break; case 0: if (curChar == 91) jjCheckNAddTwoStates(1, 2); break; case 1: if ((0xffffffffdfffffffL & l) != 0L) jjCheckNAddStates(11, 13); break; case 2: if (curChar == 93) jjstateSet[jjnewStateCnt++] = 3; break; case 3: if ((0xffffffffdfffffffL & l) != 0L) jjCheckNAddStates(14, 16); break; case 4: if (curChar == 93 && kind > 9) kind = 9; break; case 5: if (curChar == 93) jjstateSet[jjnewStateCnt++] = 4; break; case 6: if ((0xffffffffdfffffffL & l) != 0L) jjCheckNAddStates(17, 20); break; case 8: if (curChar == 94) jjCheckNAdd(9); break; case 9: if ((0x7fffffe07fffffeL & l) == 0L) break; if (kind > 15) kind = 15; jjCheckNAdd(9); break; case 11: if ((0x7fffffe07fffffeL & l) == 0L) break; if (kind > 16) kind = 16; jjCheckNAdd(11); break; case 12: if (curChar == 94) jjstateSet[jjnewStateCnt++] = 10; break; case 16: if ((0xf8000001f8000001L & l) != 0L && kind > 32) kind = 32; break; case 17: if ((0x7fffffe07fffffeL & l) == 0L) break; if (kind > 23) kind = 23; jjCheckNAddStates(4, 8); break; case 18: if ((0x7fffffe07fffffeL & l) != 0L) jjCheckNAddTwoStates(18, 19); break; case 19: if (curChar == 64) jjCheckNAdd(20); break; case 20: if ((0x7fffffe07fffffeL & l) != 0L) jjCheckNAddTwoStates(20, 21); break; case 22: if ((0x7fffffe07fffffeL & l) == 0L) break; if (kind > 19) kind = 19; jjCheckNAdd(23); break; case 23: if ((0x7fffffe07fffffeL & l) == 0L) break; if (kind > 19) kind = 19; jjCheckNAddStates(21, 23); break; case 24: if ((0x7fffffe07fffffeL & l) != 0L) jjCheckNAddTwoStates(24, 25); break; case 26: if ((0x47fffffe87ffffffL & l) == 0L) break; if (kind > 20) kind = 20; jjCheckNAddStates(24, 26); break; case 27: if ((0x47fffffe87ffffffL & l) == 0L) break; if (kind > 20) kind = 20; jjCheckNAdd(27); break; case 28: if ((0x47fffffe87ffffffL & l) != 0L) jjCheckNAddTwoStates(28, 29); break; case 30: jjAddStates(37, 38); break; case 32: if ((0x7fffffe07fffffeL & l) == 0L) break; if (kind > 23) kind = 23; jjCheckNAdd(32); break; case 33: if ((0x7fffffeL & l) != 0L) jjCheckNAddStates(0, 3); break; case 34: if ((0x7fffffeL & l) != 0L) jjCheckNAddTwoStates(34, 35); break; case 35: if ((0x7fffffe00000000L & l) == 0L) break; if (kind > 21) kind = 21; jjCheckNAddTwoStates(35, 36); break; case 36: if ((0x7fffffeL & l) == 0L) break; if (kind > 21) kind = 21; jjCheckNAddStates(27, 29); break; case 37: if ((0x7fffffeL & l) != 0L) jjCheckNAddTwoStates(37, 38); break; case 38: if ((0x7fffffe00000000L & l) != 0L) jjCheckNAddStates(30, 32); break; case 39: if (curChar == 96 && kind > 22) kind = 22; break; case 40: if ((0x7fffffeL & l) != 0L) jjCheckNAddStates(33, 36); break; default : break; } } while(i != startsAt); } else { int i2 = (curChar & 0xff) >> 6; long l2 = 1L << (curChar & 077); MatchLoop: do { switch(jjstateSet[--i]) { case 7: if ((jjbitVec0[i2] & l2) != 0L && kind > 32) kind = 32; break; case 49: case 1: if ((jjbitVec0[i2] & l2) != 0L) jjCheckNAddStates(11, 13); break; case 48: if ((jjbitVec0[i2] & l2) != 0L) jjCheckNAddStates(11, 13); break; case 3: if ((jjbitVec0[i2] & l2) != 0L) jjCheckNAddStates(14, 16); break; case 6: if ((jjbitVec0[i2] & l2) != 0L) jjCheckNAddStates(17, 20); break; case 30: if ((jjbitVec0[i2] & l2) != 0L) jjAddStates(37, 38); break; default : break; } } while(i != startsAt); } if (kind != 0x7fffffff) { jjmatchedKind = kind; jjmatchedPos = curPos; kind = 0x7fffffff; } ++curPos; if ((i = jjnewStateCnt) == (startsAt = 48 - (jjnewStateCnt = startsAt))) return curPos; try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { return curPos; } }}
if ((jjbitVec0[i2] & l2) != 0L)
if (jjCanMove_0(hiByte, i1, i2, l1, l2))
private final int jjMoveNfa_0(int startState, int curPos){ int[] nextStates; int startsAt = 0; jjnewStateCnt = 48; int i = 1; jjstateSet[0] = startState; int j, kind = 0x7fffffff; for (;;) { if (++jjround == 0x7fffffff) ReInitRounds(); if (curChar < 64) { long l = 1L << curChar; MatchLoop: do { switch(jjstateSet[--i]) { case 10: case 9: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 15) kind = 15; jjCheckNAdd(9); break; case 7: if ((0xfc00ffffffffffffL & l) != 0L) { if (kind > 32) kind = 32; } else if ((0x3ff000000000000L & l) != 0L) jjCheckNAddStates(0, 3); if ((0x3ff000000000000L & l) != 0L) { if (kind > 23) kind = 23; jjCheckNAddStates(4, 8); } else if ((0x100000200L & l) != 0L) { if (kind > 27) kind = 27; } else if (curChar == 13) jjAddStates(9, 10); else if (curChar == 10) { if (kind > 25) kind = 25; jjCheckNAddTwoStates(42, 44); } if (curChar == 32) jjstateSet[jjnewStateCnt++] = 14; break; case 49: case 1: jjCheckNAddStates(11, 13); break; case 48: jjCheckNAddStates(11, 13); break; case 3: jjCheckNAddStates(14, 16); break; case 6: jjCheckNAddStates(17, 20); break; case 11: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 16) kind = 16; jjstateSet[jjnewStateCnt++] = 11; break; case 13: if (curChar == 32) jjstateSet[jjnewStateCnt++] = 14; break; case 14: if (curChar == 32 && kind > 26) kind = 26; break; case 15: if ((0x100000200L & l) != 0L && kind > 27) kind = 27; break; case 16: if ((0xfc00ffffffffffffL & l) != 0L && kind > 32) kind = 32; break; case 17: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 23) kind = 23; jjCheckNAddStates(4, 8); break; case 18: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddTwoStates(18, 19); break; case 20: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddTwoStates(20, 21); break; case 21: if (curChar == 46) jjstateSet[jjnewStateCnt++] = 22; break; case 22: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 19) kind = 19; jjCheckNAdd(23); break; case 23: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 19) kind = 19; jjCheckNAddStates(21, 23); break; case 24: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddTwoStates(24, 25); break; case 25: if (curChar == 58) jjstateSet[jjnewStateCnt++] = 26; break; case 26: if ((0xa7ffe06000000000L & l) == 0L) break; if (kind > 20) kind = 20; jjCheckNAddStates(24, 26); break; case 27: if ((0xa7ffe06000000000L & l) == 0L) break; if (kind > 20) kind = 20; jjCheckNAdd(27); break; case 28: if ((0xa7ffe06000000000L & l) != 0L) jjCheckNAddTwoStates(28, 29); break; case 29: if (curChar == 40) jjCheckNAdd(30); break; case 30: if ((0xfffffdffffffdbffL & l) != 0L) jjCheckNAddTwoStates(30, 31); break; case 31: if (curChar == 41 && kind > 20) kind = 20; break; case 32: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 23) kind = 23; jjCheckNAdd(32); break; case 33: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddStates(0, 3); break; case 34: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddTwoStates(34, 35); break; case 35: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 21) kind = 21; jjCheckNAddTwoStates(35, 36); break; case 36: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 21) kind = 21; jjCheckNAddStates(27, 29); break; case 37: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddTwoStates(37, 38); break; case 38: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddStates(30, 32); break; case 40: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddStates(33, 36); break; case 41: if (curChar != 10) break; if (kind > 25) kind = 25; jjCheckNAddTwoStates(42, 44); break; case 42: case 43: if (curChar == 10 && kind > 24) kind = 24; break; case 44: if (curChar == 13) jjstateSet[jjnewStateCnt++] = 43; break; case 45: if (curChar == 13) jjAddStates(9, 10); break; case 46: if (curChar == 10) jjCheckNAddTwoStates(42, 44); break; case 47: if (curChar == 10 && kind > 25) kind = 25; break; default : break; } } while(i != startsAt); } else if (curChar < 128) { long l = 1L << (curChar & 077); MatchLoop: do { switch(jjstateSet[--i]) { case 10: if ((0x7fffffe07fffffeL & l) != 0L) { if (kind > 15) kind = 15; jjCheckNAdd(9); } else if (curChar == 64) { if (kind > 16) kind = 16; jjCheckNAdd(11); } break; case 7: if ((0x7fffffe07fffffeL & l) != 0L) { if (kind > 23) kind = 23; jjCheckNAddStates(4, 8); } else if ((0xf8000001f8000001L & l) != 0L) { if (kind > 32) kind = 32; } if ((0x7fffffeL & l) != 0L) jjCheckNAddStates(0, 3); else if (curChar == 94) jjstateSet[jjnewStateCnt++] = 10; else if (curChar == 91) jjstateSet[jjnewStateCnt++] = 0; if (curChar == 94) jjCheckNAdd(9); break; case 49: if ((0xffffffffdfffffffL & l) != 0L) jjCheckNAddStates(11, 13); else if (curChar == 93) jjstateSet[jjnewStateCnt++] = 4; if (curChar == 93) jjstateSet[jjnewStateCnt++] = 3; break; case 48: if ((0xffffffffdfffffffL & l) != 0L) jjCheckNAddStates(11, 13); else if (curChar == 93) jjstateSet[jjnewStateCnt++] = 3; break; case 0: if (curChar == 91) jjCheckNAddTwoStates(1, 2); break; case 1: if ((0xffffffffdfffffffL & l) != 0L) jjCheckNAddStates(11, 13); break; case 2: if (curChar == 93) jjstateSet[jjnewStateCnt++] = 3; break; case 3: if ((0xffffffffdfffffffL & l) != 0L) jjCheckNAddStates(14, 16); break; case 4: if (curChar == 93 && kind > 9) kind = 9; break; case 5: if (curChar == 93) jjstateSet[jjnewStateCnt++] = 4; break; case 6: if ((0xffffffffdfffffffL & l) != 0L) jjCheckNAddStates(17, 20); break; case 8: if (curChar == 94) jjCheckNAdd(9); break; case 9: if ((0x7fffffe07fffffeL & l) == 0L) break; if (kind > 15) kind = 15; jjCheckNAdd(9); break; case 11: if ((0x7fffffe07fffffeL & l) == 0L) break; if (kind > 16) kind = 16; jjCheckNAdd(11); break; case 12: if (curChar == 94) jjstateSet[jjnewStateCnt++] = 10; break; case 16: if ((0xf8000001f8000001L & l) != 0L && kind > 32) kind = 32; break; case 17: if ((0x7fffffe07fffffeL & l) == 0L) break; if (kind > 23) kind = 23; jjCheckNAddStates(4, 8); break; case 18: if ((0x7fffffe07fffffeL & l) != 0L) jjCheckNAddTwoStates(18, 19); break; case 19: if (curChar == 64) jjCheckNAdd(20); break; case 20: if ((0x7fffffe07fffffeL & l) != 0L) jjCheckNAddTwoStates(20, 21); break; case 22: if ((0x7fffffe07fffffeL & l) == 0L) break; if (kind > 19) kind = 19; jjCheckNAdd(23); break; case 23: if ((0x7fffffe07fffffeL & l) == 0L) break; if (kind > 19) kind = 19; jjCheckNAddStates(21, 23); break; case 24: if ((0x7fffffe07fffffeL & l) != 0L) jjCheckNAddTwoStates(24, 25); break; case 26: if ((0x47fffffe87ffffffL & l) == 0L) break; if (kind > 20) kind = 20; jjCheckNAddStates(24, 26); break; case 27: if ((0x47fffffe87ffffffL & l) == 0L) break; if (kind > 20) kind = 20; jjCheckNAdd(27); break; case 28: if ((0x47fffffe87ffffffL & l) != 0L) jjCheckNAddTwoStates(28, 29); break; case 30: jjAddStates(37, 38); break; case 32: if ((0x7fffffe07fffffeL & l) == 0L) break; if (kind > 23) kind = 23; jjCheckNAdd(32); break; case 33: if ((0x7fffffeL & l) != 0L) jjCheckNAddStates(0, 3); break; case 34: if ((0x7fffffeL & l) != 0L) jjCheckNAddTwoStates(34, 35); break; case 35: if ((0x7fffffe00000000L & l) == 0L) break; if (kind > 21) kind = 21; jjCheckNAddTwoStates(35, 36); break; case 36: if ((0x7fffffeL & l) == 0L) break; if (kind > 21) kind = 21; jjCheckNAddStates(27, 29); break; case 37: if ((0x7fffffeL & l) != 0L) jjCheckNAddTwoStates(37, 38); break; case 38: if ((0x7fffffe00000000L & l) != 0L) jjCheckNAddStates(30, 32); break; case 39: if (curChar == 96 && kind > 22) kind = 22; break; case 40: if ((0x7fffffeL & l) != 0L) jjCheckNAddStates(33, 36); break; default : break; } } while(i != startsAt); } else { int i2 = (curChar & 0xff) >> 6; long l2 = 1L << (curChar & 077); MatchLoop: do { switch(jjstateSet[--i]) { case 7: if ((jjbitVec0[i2] & l2) != 0L && kind > 32) kind = 32; break; case 49: case 1: if ((jjbitVec0[i2] & l2) != 0L) jjCheckNAddStates(11, 13); break; case 48: if ((jjbitVec0[i2] & l2) != 0L) jjCheckNAddStates(11, 13); break; case 3: if ((jjbitVec0[i2] & l2) != 0L) jjCheckNAddStates(14, 16); break; case 6: if ((jjbitVec0[i2] & l2) != 0L) jjCheckNAddStates(17, 20); break; case 30: if ((jjbitVec0[i2] & l2) != 0L) jjAddStates(37, 38); break; default : break; } } while(i != startsAt); } if (kind != 0x7fffffff) { jjmatchedKind = kind; jjmatchedPos = curPos; kind = 0x7fffffff; } ++curPos; if ((i = jjnewStateCnt) == (startsAt = 48 - (jjnewStateCnt = startsAt))) return curPos; try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { return curPos; } }}
this.iterationCount = _wm.getBroker().getIntegerSetting("TestSyntheticTemplate.IterationCount", this.threadCount);
this.iterationCount = _wm.getBroker().getIntegerSetting("TestSyntheticTemplate.IterationCount", this.IterationCount);
public static Test suite() { TestSuite suite= new TestSuite(); suite.addTest(new TestSyntheticTemplate("load") { protected WebMacro createWebMacro() throws Exception { return new WM("org/webmacro/template/TST.properties"); } protected void runTest() throws Exception { this.threadCount = _wm.getBroker().getIntegerSetting("TestSyntheticTemplate.ThreadCount", this.threadCount); this.iterationCount = _wm.getBroker().getIntegerSetting("TestSyntheticTemplate.IterationCount", this.threadCount); this.testLoadAndToss(); this.testLoad(); } } ); return suite; }
this.iterationCount = _wm.getBroker().getIntegerSetting("TestSyntheticTemplate.IterationCount", this.threadCount);
this.iterationCount = _wm.getBroker().getIntegerSetting("TestSyntheticTemplate.IterationCount", this.IterationCount);
protected void runTest() throws Exception { this.threadCount = _wm.getBroker().getIntegerSetting("TestSyntheticTemplate.ThreadCount", this.threadCount); this.iterationCount = _wm.getBroker().getIntegerSetting("TestSyntheticTemplate.IterationCount", this.threadCount); this.testLoadAndToss(); this.testLoad(); }
SelectList sl = new SelectList(fruits, 3); context.put("sl-fruits", sl);
public static void main(String arg[]) { Log.traceExceptions(true); Log.setLevel(Log.ALL); Log.setTarget(System.err); if (arg.length != 0) { System.out.println("Enabling log types"); Log.enableTypes(arg); } // Build a context WebMacro wm = null; Hashtable context = null; try { wm = new WM(); context = new Hashtable(); Object names[] = { "prop" }; PropertyOperator.setProperty(context, names, "Example property"); } catch (Exception e) { e.printStackTrace(); } context.put("helloworld", "Hello World"); context.put("hello", "Hello"); context.put("file", "include.txt"); TestObject[] fruits = { new TestObject("apple",false), new TestObject("lemon",true), new TestObject("pear",false), new TestObject("orange",true), new TestObject("watermelon",false), new TestObject("peach",false), new TestObject("lime",true) }; context.put("fruits", fruits); context.put("flipper", new TestObject("flip",false)); System.out.println("*** CONTEXT ***"); { Enumeration elem = context.keys(); while (elem.hasMoreElements()) { Object key = elem.nextElement(); System.out.println("context: " + key + " --> " + context.get(key)); } } System.out.println("- - - - - - - - - - - - - - - - - - - -"); try { Template t1 = new StreamTemplate(wm.getBroker(), new InputStreamReader(System.in)); t1.parse(); System.out.println("*** PARAMETERS ***"); { Iterator i = t1.getParameterNames(); while (i.hasNext()) { String key = (String) i.next(); System.out.println("param: " + key + " --> " + t1.getParam(key)); } } Writer w = new OutputStreamWriter(System.out); System.out.println("*** RESULT ***"); t1.write(w,context); w.close(); System.out.println("*** DONE ***"); //System.out.println(result); } catch (Exception e) { e.printStackTrace(); } }
else {
else if (!selected && boldWhenActive) { textLabel.setFont(defaultFont); } else if(selected){ textLabel.setFont(defaultFont);
public void setSelected(boolean selected) { super.setSelected(selected); this.selected = selected; if (boldWhenActive && selected) { textLabel.setFont(textLabel.getFont().deriveFont(Font.BOLD)); } else { // textLabel.setFont(defaultFont); } invalidate(); repaint(); }
return new XBeanNamespaceHandlerResolver(getBeanClassLoader());
ClassLoader classLoader = getBeanClassLoader(); if (classLoader == null) { classLoader = Thread.currentThread().getContextClassLoader(); } return new XBeanNamespaceHandlerResolver(classLoader);
protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver() { return new XBeanNamespaceHandlerResolver(getBeanClassLoader()); }
URL url = _broker.getResource(resource);
URL url = null; ClassLoader cl = this.getClass().getClassLoader(); if (cl != null) { url = cl.getResource(resource); } else { url = ClassLoader.getSystemResource(resource); }
private final URL searchClasspath(String resource) { _log.debug("Searching classpath for "+resource); URL url = _broker.getResource(resource); if (url != null) { return url; } /* * look for locale specific resources AAAA{_xxxx_yyyyy_....}BBBBB */ String[] parts = parseLocalePath(resource); if (parts != null) { if (parts[1] != null) { resource = buildPath(parts[0],parts[1], parts[2]); return searchClasspath(resource); } } return null; }
if (!isEmpty(uri) || !reservedElementNames.contains(localName)) {
if (uri == null || uri.equals(SPRING_SCHEMA)) { if (BEAN_ELEMENT.equals(localName)) { return parseBeanDefinitionElement(childElement, true); } } else {
protected Object parseChildExtensionBean(Element element) { NodeList nl = element.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element) { Element childElement = (Element) node; String uri = childElement.getNamespaceURI(); String localName = childElement.getLocalName(); if (!isEmpty(uri) || !reservedElementNames.contains(localName)) { Object value = parseBeanFromExtensionElement(childElement); if (value != null) { return value; } } else if (isEmpty(uri)) { if (BEAN_ELEMENT.equals(localName)) { return parseBeanDefinitionElement(childElement, true); } } } } return null; }
} } else if (isEmpty(uri)) { if (BEAN_ELEMENT.equals(localName)) { return parseBeanDefinitionElement(childElement, true);
protected Object parseChildExtensionBean(Element element) { NodeList nl = element.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element) { Element childElement = (Element) node; String uri = childElement.getNamespaceURI(); String localName = childElement.getLocalName(); if (!isEmpty(uri) || !reservedElementNames.contains(localName)) { Object value = parseBeanFromExtensionElement(childElement); if (value != null) { return value; } } else if (isEmpty(uri)) { if (BEAN_ELEMENT.equals(localName)) { return parseBeanDefinitionElement(childElement, true); } } } } return null; }
if (_log != null) { _log.info("target: " + t); }
public void addTarget(LogTarget t) { _targets.add(t); Enumeration s = _sources.elements(); while (s.hasMoreElements()) { LogSource l = (LogSource) s.nextElement(); t.attach(l); } }
InputStream _is = null; try { _is = url.openStream(); t = new URLTemplate(_broker,url); _log.debug("**PARSING "+url); t.parse(); return t; } finally { if (_is != null) _is.close(); }
t = new URLTemplate(_broker,url); _log.debug("**PARSING "+url); t.parse(); return t;
final private Template getTemplate(URL path) { _log.debug("get:"+path); URLTemplate t; String pre = null; String mid = null; String post = null; String pathStr = path.toExternalForm(); try { String[] parts = parseLocalePath(pathStr); String urlPath = null; URL url = path; if (parts == null) { urlPath = pathStr; } else { pre = parts[0]; mid = parts[1]; post = parts[2]; urlPath = pre+((mid == null) ? "" : mid)+post; url = new URL(urlPath); } if (urlPath.length() > 512) { throw new IllegalArgumentException("URL path too long: "+urlPath); } _log.debug("URLTemplateProvider: loading " + url+ "("+path+","+urlPath+")"); /* * Seems a bit wasteful to check the URL here but t.parse() * generates "spurious" errors if the template doesn't exist */ InputStream _is = null; try { _is = url.openStream(); t = new URLTemplate(_broker,url); _log.debug("**PARSING "+url); t.parse(); return t; } finally { if (_is != null) _is.close(); } } catch (IOException e) { _log.debug(e.getClass().getName()+" "+e.getMessage()); // try the next locale if (mid != null) { try { String p = buildPath(pre,mid,post); if (path != null) { return (Template) _broker.get(_TYPE,p); } else { return (Template) _broker.get(_TYPE,p); } } catch (Exception ex) { _log.debug(ex.getClass().getName()+" "+ex.getMessage()); // ignore } } _log.error("URLTemplateProvider(1): Could not load template: "+ path,e); } catch (Exception e) { _log.error("URLTemplateProvider(2): Could not load template: "+ path,e); } _log.debug("URLTemplateProvider: " + path + " not found."); return null; }
if("create".equals(iwc.getParameter(ContentViewer.PARAMETER_CONTENT_RESOURCE))){
if("create".equals(iwc.getParameter(ContentViewer.PARAMETER_ACTION))){
public void encodeBegin(FacesContext context) throws IOException { if(clearOnInit) { //WFUtil.invoke(ARTICLE_ITEM_BEAN_ID, "clear"); ArticleItemBean bean = getArticleItemBean(); if(bean!=null){ bean.clear(); } } // WFUtil.invoke(ARTICLE_ITEM_BEAN_ID, "updateLocale");// updateEditButtons(); super.encodeBegin(context); IWContext iwc = IWContext.getIWContext(context); String resourcePath = iwc.getParameter(ContentViewer.PARAMETER_CONTENT_RESOURCE); if(resourcePath!=null){ if("create".equals(iwc.getParameter(ContentViewer.PARAMETER_CONTENT_RESOURCE))){ //WFUtil.invoke(ARTICLE_ITEM_BEAN_ID,"setFolderLocation",resourcePath,String.class); getArticleItemBean().setFolderLocation(resourcePath); } else { //WFUtil.invoke(ARTICLE_ITEM_BEAN_ID,"load",resourcePath,String.class); try { getArticleItemBean().load(resourcePath); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } WebDAVCategories categoriesUI = (WebDAVCategories)getCategoryEditor(); //Update the categoriesUI with the resourcePath given: if(!isInCreateMode()&& categoriesUI!=null){ //there is no resourcepath set for the article if it's about to be created categoriesUI.setResourcePath(resourcePath); } }// if(((Boolean)WFUtil.invoke(ARTICLE_ITEM_BEAN_ID,"getLanguageChange")).booleanValue()) { String languageChange=(String)WFUtil.invoke(ARTICLE_ITEM_BEAN_ID,"getLanguageChange"); if(languageChange!=null) { String articlePath = (String)WFUtil.invoke(ARTICLE_ITEM_BEAN_ID, "getArticlePath"); if(null!=articlePath && articlePath.length()>0) { boolean result = ((Boolean)WFUtil.invoke(ARTICLE_ITEM_BEAN_ID, "load",articlePath+"/"+languageChange+ArticleItemBean.ARTICLE_SUFFIX)).booleanValue(); if(!result) { System.out.println("Warning loading new language did not work!"); } } WFUtil.invoke(ARTICLE_ITEM_BEAN_ID, "setLanguageChange",""); } }
buf.append(RESOURCE_DIRECTORY.getAbsolutePath()).append(";");
try { buf.append(RESOURCE_DIRECTORY.getCanonicalPath()).append(";"); } catch (IOException e) { e.printStackTrace(); }
public static void main(final String[] args) { EnhancedDebuggerWindow.PERSISTED_DEBUGGER = true; EnhancedDebuggerWindow.MAX_TABLE_ROWS = 10; XMPPConnection.DEBUG_ENABLED = true; String current = System.getProperty("java.library.path"); String classPath = System.getProperty("java.class.path"); // Set UIManager properties for JTree System.setProperty("apple.laf.useScreenMenuBar", "true"); /** Update Library Path **/ StringBuffer buf = new StringBuffer(); buf.append(current); buf.append(";"); final String workingDirectory = System.getProperty("appdir"); if (workingDirectory == null) { RESOURCE_DIRECTORY = new File(USER_HOME, "/Spark/resources").getAbsoluteFile(); BIN_DIRECTORY = new File(USER_HOME, "/Spark/bin").getAbsoluteFile(); LOG_DIRECTORY = new File(USER_HOME, "/Spark/logs").getAbsoluteFile(); RESOURCE_DIRECTORY.mkdirs(); LOG_DIRECTORY.mkdirs(); if (!RESOURCE_DIRECTORY.exists() || !LOG_DIRECTORY.exists()) { JOptionPane.showMessageDialog(new JFrame(), "Unable to create directories necessary for runtime.", "Spark Error", JOptionPane.ERROR_MESSAGE); System.exit(1); } } else { // This is the installed executable. File workingDir = new File(workingDirectory); RESOURCE_DIRECTORY = new File(workingDir, "resources").getAbsoluteFile(); BIN_DIRECTORY = new File(workingDir, "bin").getAbsoluteFile(); LOG_DIRECTORY = new File(USER_HOME, "/Spark/logs").getAbsoluteFile(); LOG_DIRECTORY.mkdirs(); buf.append(RESOURCE_DIRECTORY.getAbsolutePath()).append(";"); } buf.append(classPath); // Update System Properties System.setProperty("java.library.path", buf.toString()); System.setProperty("sun.java2d.noddraw", "true"); SwingUtilities.invokeLater(new Runnable() { public void run() { // Start Application new Spark(); } }); // Handle arguments if (args.length > 0) { argument = args[0]; } }
createException = new MockCreateException();
assertValidServiceContext(serviceContext); this.serviceContext = serviceContext; createException = new MockCreateException("MockCreateException");
public Object createService(ServiceContext serviceContext) { createException = new MockCreateException(); if (throwExceptionFromCreate) throw createException; return super.createService(serviceContext); }
destroyException = new MockDestroyException();
assertSame(this.serviceContext, serviceContext); assertValidServiceContext(serviceContext); destroyException = new MockDestroyException("MockDestroyException");
public void destroyService(ServiceContext serviceContext) { destroyException = new MockDestroyException(); if (throwExceptionFromDestroy) throw destroyException; super.destroyService(serviceContext); }
public Set getStartConditions() {
public synchronized Set getStartConditions() {
public Set getStartConditions() { Set startConditions = new HashSet(super.getStartConditions()); startConditions.add(startCondition); return startConditions; }
public Set getStopConditions() {
public synchronized Set getStopConditions() {
public Set getStopConditions() { Set stopConditions = new HashSet(super.getStopConditions()); stopConditions.add(stopCondition); return stopConditions; }
assertValidEvent(serviceEvent, false);
public void serviceRegistered(ServiceEvent serviceEvent) { registered = serviceEvent; }
assertValidEvent(serviceEvent, true);
public void serviceRunning(ServiceEvent serviceEvent) { running = serviceEvent; }
assertValidEvent(serviceEvent, false);
public void serviceStartError(ServiceEvent serviceEvent) { startError = serviceEvent; }
assertValidEvent(serviceEvent, false);
public void serviceStarting(ServiceEvent serviceEvent) { starting = serviceEvent; }
assertValidEvent(serviceEvent, false);
public void serviceStopError(ServiceEvent serviceEvent) { stopError = serviceEvent; }
assertValidEvent(serviceEvent, false);
public void serviceStopped(ServiceEvent serviceEvent) { stopped = serviceEvent; }
assertValidEvent(serviceEvent, false);
public void serviceStopping(ServiceEvent serviceEvent) { stopping = serviceEvent; }
assertValidEvent(serviceEvent, false);
public void serviceUnregistered(ServiceEvent serviceEvent) { unregistered = serviceEvent; }
assertValidEvent(serviceEvent, false);
public void serviceWaitingToStart(ServiceEvent serviceEvent) { waitingToStart = serviceEvent; }
assertValidEvent(serviceEvent, true);
public void serviceWaitingToStop(ServiceEvent serviceEvent) { waitingToStop = serviceEvent; }
assertValidServiceConditionContext(context);
public void initialize(ServiceConditionContext context) { initializeCalled = true; this.context = context; if (initializedSignal != null) { initializedSignal.countDown(); } }
} else if (serviceFactory.throwExceptionFromDestroy != true) {
} else if (!serviceFactory.throwExceptionFromDestroy) {
private void destroy(StopStrategy stopStrategy) { ServiceState initialState = serviceManager.getState(); serviceMonitor.reset(); startCondition.reset(); stopCondition.reset(); kernel.reset(); try { serviceManager.destroy(stopStrategy); } catch (IllegalServiceStateException e) { assertFalse(stopCondition.satisfied); assertSame(StopStrategies.ASYNCHRONOUS, stopStrategy); } catch (UnsatisfiedConditionsException e) { assertFalse(stopCondition.satisfied); assertSame(StopStrategies.SYNCHRONOUS, stopStrategy); assertTrue(e.getUnsatisfiedConditions().contains(stopCondition)); } if (serviceFactory.restartable || initialState == ServiceState.STOPPED) { assertSame(ServiceState.STOPPED, serviceManager.getState()); assertSame(serviceName, serviceManager.getServiceName()); assertSame(serviceFactory, serviceManager.getServiceFactory()); assertSame(classLoader, serviceManager.getClassLoader()); assertEquals(0, serviceManager.getStartTime()); assertNull(serviceManager.getService()); // verify expected events fired assertNull(serviceMonitor.registered); assertNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNull(serviceMonitor.running); assertNull(serviceMonitor.stopping); assertNull(serviceMonitor.waitingToStop); assertNull(serviceMonitor.stopError); assertNull(serviceMonitor.stopped); assertNotNull(serviceMonitor.unregistered); } else if (!stopCondition.satisfied && stopStrategy != StopStrategies.FORCE) { assertSame(ServiceState.RUNNING, serviceManager.getState()); assertSame(serviceName, serviceManager.getServiceName()); assertSame(serviceFactory, serviceManager.getServiceFactory()); assertSame(classLoader, serviceManager.getClassLoader()); assertTrue(serviceManager.getStartTime() > 0); assertNotNull(serviceManager.getService()); assertNull(serviceMonitor.registered); assertNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNull(serviceMonitor.running); assertNull(serviceMonitor.stopping); if (stopStrategy == StopStrategies.ASYNCHRONOUS) { assertNotNull(serviceMonitor.waitingToStop); assertTrue(serviceMonitor.waitingToStop.getUnsatisfiedConditions().contains(stopCondition)); } else { assertNull(serviceMonitor.waitingToStop); } assertNull(serviceMonitor.stopError); assertNull(serviceMonitor.stopped); assertNull(serviceMonitor.unregistered); } else if (serviceFactory.throwExceptionFromDestroy != true) { assertSame(ServiceState.STOPPED, serviceManager.getState()); assertEquals(0, serviceManager.getStartTime()); assertNull(serviceManager.getService()); assertNull(serviceMonitor.registered); assertNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNull(serviceMonitor.running); assertNotNull(serviceMonitor.stopping); assertNull(serviceMonitor.waitingToStop); if (!stopCondition.satisfied && stopStrategy == StopStrategies.FORCE) { assertNotNull(serviceMonitor.stopError); } else { assertNull(serviceMonitor.stopError); } assertNotNull(serviceMonitor.stopped); assertNotNull(serviceMonitor.unregistered); if (!stopCondition.satisfied && stopStrategy == StopStrategies.FORCE) { assertEquals(serviceMonitor.stopError.getEventId() + 1, serviceMonitor.stopping.getEventId()); assertEquals(serviceMonitor.stopError.getEventId() + 2, serviceMonitor.stopped.getEventId()); assertEquals(serviceMonitor.stopError.getEventId() + 3, serviceMonitor.unregistered.getEventId()); } else { assertEquals(serviceMonitor.stopping.getEventId() + 1, serviceMonitor.stopped.getEventId()); assertEquals(serviceMonitor.stopping.getEventId() + 2, serviceMonitor.unregistered.getEventId()); } assertFalse(startCondition.initializeCalled); assertFalse(startCondition.isSatisfiedCalled); assertTrue(startCondition.destroyCalled); // There is no way to determine if the init should have been called // stopCondition.initializeCalled assertTrue(stopCondition.isSatisfiedCalled); assertTrue(stopCondition.destroyCalled); } else { assertSame(ServiceState.STOPPED, serviceManager.getState()); assertEquals(0, serviceManager.getStartTime()); assertNull(serviceManager.getService()); assertNull(serviceMonitor.registered); assertNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNull(serviceMonitor.running); assertNotNull(serviceMonitor.stopping); assertNull(serviceMonitor.waitingToStop); assertNotNull(serviceMonitor.stopError); assertNotNull(serviceMonitor.stopped); assertNotNull(serviceMonitor.unregistered); assertEquals(serviceMonitor.stopping.getEventId() + 1, serviceMonitor.stopError.getEventId()); assertEquals(serviceMonitor.stopping.getEventId() + 2, serviceMonitor.stopped.getEventId()); assertEquals(serviceMonitor.stopping.getEventId() + 3, serviceMonitor.unregistered.getEventId()); assertFalse(startCondition.initializeCalled); assertFalse(startCondition.isSatisfiedCalled); assertTrue(startCondition.destroyCalled); assertTrue(stopCondition.initializeCalled); assertTrue(stopCondition.isSatisfiedCalled); assertTrue(stopCondition.destroyCalled); } }
assertEquals(serviceName, e.getServiceName());
private void disabledStart(StartStrategy startStrategy) throws Exception { serviceFactory.setEnabled(false); try { serviceManager.start(false, startStrategy); fail("A disabled service should throw an IllegalServiceStateException from start"); } catch (IllegalServiceStateException e) { // expected } // move to starting disable, move to running, and try to restart serviceFactory.setEnabled(true); startCondition.satisfied = false; start(false, StartStrategies.ASYNCHRONOUS); serviceFactory.setEnabled(false); startCondition.satisfied = true; start(false, startStrategy); start(false, startStrategy); stop(StopStrategies.ASYNCHRONOUS); try { serviceManager.start(false, startStrategy); fail("A disabled service should throw an IllegalServiceStateException from start"); } catch (IllegalServiceStateException e) { // expected } }
assertTrue(serviceFactory.throwExceptionFromCreate == true);
assertTrue(serviceFactory.throwExceptionFromCreate);
private void initialize() throws Exception { long now = System.currentTimeMillis(); // introduce a bit of delay so subsequent times are much less likely to equal to not Thread.sleep(50); serviceMonitor.reset(); startCondition.reset(); stopCondition.reset(); kernel.reset(); try { serviceManager.initialize(); } catch (MockCreateException e) { assertTrue(serviceFactory.throwExceptionFromCreate == true); assertSame(serviceFactory.createException, e); } catch (UnsatisfiedConditionsException e) { assertTrue(startCondition.satisfied == false); assertTrue(e.getUnsatisfiedConditions().contains(startCondition)); } catch (IllegalServiceStateException e) { assertFalse(serviceFactory.isEnabled()); } assertSame(serviceName, serviceManager.getServiceName()); assertSame(serviceFactory, serviceManager.getServiceFactory()); assertSame(classLoader, serviceManager.getClassLoader()); if (serviceFactory.restartable) { assertSame(ServiceState.STOPPED, serviceManager.getState()); assertEquals(0, serviceManager.getStartTime()); assertNull(serviceManager.getService()); assertNotNull(serviceMonitor.registered); assertNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNull(serviceMonitor.running); assertNull(serviceMonitor.stopping); assertNull(serviceMonitor.waitingToStop); assertNull(serviceMonitor.stopError); assertNull(serviceMonitor.stopped); assertNull(serviceMonitor.unregistered); assertFalse(startCondition.initializeCalled); assertFalse(startCondition.isSatisfiedCalled); assertFalse(startCondition.destroyCalled); assertFalse(stopCondition.initializeCalled); assertFalse(stopCondition.isSatisfiedCalled); assertFalse(stopCondition.destroyCalled); } else if (!serviceFactory.isEnabled()) { assertSame(ServiceState.STOPPED, serviceManager.getState()); assertEquals(0, serviceManager.getStartTime()); assertNull(serviceManager.getService()); assertNull(serviceMonitor.registered); assertNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNull(serviceMonitor.running); assertNull(serviceMonitor.stopping); assertNull(serviceMonitor.stopError); assertNull(serviceMonitor.stopped); assertNull(serviceMonitor.unregistered); assertFalse(startCondition.initializeCalled); assertFalse(startCondition.isSatisfiedCalled); assertFalse(startCondition.destroyCalled); assertFalse(stopCondition.initializeCalled); assertFalse(stopCondition.isSatisfiedCalled); assertFalse(stopCondition.destroyCalled); } else if (serviceFactory.throwExceptionFromCreate != true && startCondition.satisfied == true) { assertSame(ServiceState.RUNNING, serviceManager.getState()); assertSame(SERVICE, serviceManager.getService()); assertTrue(serviceManager.getStartTime() > now); assertNotNull(serviceMonitor.registered); assertNotNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNotNull(serviceMonitor.running); assertNull(serviceMonitor.stopping); assertNull(serviceMonitor.stopError); assertNull(serviceMonitor.stopped); assertNull(serviceMonitor.unregistered); assertEquals(serviceMonitor.registered.getEventId() + 1, serviceMonitor.starting.getEventId()); assertEquals(serviceMonitor.registered.getEventId() + 2, serviceMonitor.running.getEventId()); assertTrue(startCondition.initializeCalled); assertTrue(startCondition.isSatisfiedCalled); assertFalse(startCondition.destroyCalled); assertFalse(stopCondition.initializeCalled); assertFalse(stopCondition.isSatisfiedCalled); assertFalse(stopCondition.destroyCalled); } else { assertSame(ServiceState.STOPPED, serviceManager.getState()); assertEquals(0, serviceManager.getStartTime()); assertNull(serviceManager.getService()); assertNotNull(serviceMonitor.registered); assertNotNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNull(serviceMonitor.running); assertNotNull(serviceMonitor.stopping); assertNull(serviceMonitor.stopError); assertNotNull(serviceMonitor.stopped); assertNotNull(serviceMonitor.unregistered); assertEquals(serviceMonitor.registered.getEventId() + 1, serviceMonitor.starting.getEventId()); assertEquals(serviceMonitor.registered.getEventId() + 2, serviceMonitor.stopping.getEventId()); assertEquals(serviceMonitor.registered.getEventId() + 3, serviceMonitor.stopped.getEventId()); assertEquals(serviceMonitor.registered.getEventId() + 4, serviceMonitor.unregistered.getEventId()); assertTrue(startCondition.initializeCalled); assertTrue(startCondition.isSatisfiedCalled); assertTrue(startCondition.destroyCalled); assertFalse(stopCondition.initializeCalled); assertFalse(stopCondition.isSatisfiedCalled); assertFalse(stopCondition.destroyCalled); } }
assertTrue(startCondition.satisfied == false);
assertTrue(!startCondition.satisfied);
private void initialize() throws Exception { long now = System.currentTimeMillis(); // introduce a bit of delay so subsequent times are much less likely to equal to not Thread.sleep(50); serviceMonitor.reset(); startCondition.reset(); stopCondition.reset(); kernel.reset(); try { serviceManager.initialize(); } catch (MockCreateException e) { assertTrue(serviceFactory.throwExceptionFromCreate == true); assertSame(serviceFactory.createException, e); } catch (UnsatisfiedConditionsException e) { assertTrue(startCondition.satisfied == false); assertTrue(e.getUnsatisfiedConditions().contains(startCondition)); } catch (IllegalServiceStateException e) { assertFalse(serviceFactory.isEnabled()); } assertSame(serviceName, serviceManager.getServiceName()); assertSame(serviceFactory, serviceManager.getServiceFactory()); assertSame(classLoader, serviceManager.getClassLoader()); if (serviceFactory.restartable) { assertSame(ServiceState.STOPPED, serviceManager.getState()); assertEquals(0, serviceManager.getStartTime()); assertNull(serviceManager.getService()); assertNotNull(serviceMonitor.registered); assertNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNull(serviceMonitor.running); assertNull(serviceMonitor.stopping); assertNull(serviceMonitor.waitingToStop); assertNull(serviceMonitor.stopError); assertNull(serviceMonitor.stopped); assertNull(serviceMonitor.unregistered); assertFalse(startCondition.initializeCalled); assertFalse(startCondition.isSatisfiedCalled); assertFalse(startCondition.destroyCalled); assertFalse(stopCondition.initializeCalled); assertFalse(stopCondition.isSatisfiedCalled); assertFalse(stopCondition.destroyCalled); } else if (!serviceFactory.isEnabled()) { assertSame(ServiceState.STOPPED, serviceManager.getState()); assertEquals(0, serviceManager.getStartTime()); assertNull(serviceManager.getService()); assertNull(serviceMonitor.registered); assertNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNull(serviceMonitor.running); assertNull(serviceMonitor.stopping); assertNull(serviceMonitor.stopError); assertNull(serviceMonitor.stopped); assertNull(serviceMonitor.unregistered); assertFalse(startCondition.initializeCalled); assertFalse(startCondition.isSatisfiedCalled); assertFalse(startCondition.destroyCalled); assertFalse(stopCondition.initializeCalled); assertFalse(stopCondition.isSatisfiedCalled); assertFalse(stopCondition.destroyCalled); } else if (serviceFactory.throwExceptionFromCreate != true && startCondition.satisfied == true) { assertSame(ServiceState.RUNNING, serviceManager.getState()); assertSame(SERVICE, serviceManager.getService()); assertTrue(serviceManager.getStartTime() > now); assertNotNull(serviceMonitor.registered); assertNotNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNotNull(serviceMonitor.running); assertNull(serviceMonitor.stopping); assertNull(serviceMonitor.stopError); assertNull(serviceMonitor.stopped); assertNull(serviceMonitor.unregistered); assertEquals(serviceMonitor.registered.getEventId() + 1, serviceMonitor.starting.getEventId()); assertEquals(serviceMonitor.registered.getEventId() + 2, serviceMonitor.running.getEventId()); assertTrue(startCondition.initializeCalled); assertTrue(startCondition.isSatisfiedCalled); assertFalse(startCondition.destroyCalled); assertFalse(stopCondition.initializeCalled); assertFalse(stopCondition.isSatisfiedCalled); assertFalse(stopCondition.destroyCalled); } else { assertSame(ServiceState.STOPPED, serviceManager.getState()); assertEquals(0, serviceManager.getStartTime()); assertNull(serviceManager.getService()); assertNotNull(serviceMonitor.registered); assertNotNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNull(serviceMonitor.running); assertNotNull(serviceMonitor.stopping); assertNull(serviceMonitor.stopError); assertNotNull(serviceMonitor.stopped); assertNotNull(serviceMonitor.unregistered); assertEquals(serviceMonitor.registered.getEventId() + 1, serviceMonitor.starting.getEventId()); assertEquals(serviceMonitor.registered.getEventId() + 2, serviceMonitor.stopping.getEventId()); assertEquals(serviceMonitor.registered.getEventId() + 3, serviceMonitor.stopped.getEventId()); assertEquals(serviceMonitor.registered.getEventId() + 4, serviceMonitor.unregistered.getEventId()); assertTrue(startCondition.initializeCalled); assertTrue(startCondition.isSatisfiedCalled); assertTrue(startCondition.destroyCalled); assertFalse(stopCondition.initializeCalled); assertFalse(stopCondition.isSatisfiedCalled); assertFalse(stopCondition.destroyCalled); } }
} else if (serviceFactory.throwExceptionFromCreate != true && startCondition.satisfied == true) {
} else if (!serviceFactory.throwExceptionFromCreate && startCondition.satisfied) {
private void initialize() throws Exception { long now = System.currentTimeMillis(); // introduce a bit of delay so subsequent times are much less likely to equal to not Thread.sleep(50); serviceMonitor.reset(); startCondition.reset(); stopCondition.reset(); kernel.reset(); try { serviceManager.initialize(); } catch (MockCreateException e) { assertTrue(serviceFactory.throwExceptionFromCreate == true); assertSame(serviceFactory.createException, e); } catch (UnsatisfiedConditionsException e) { assertTrue(startCondition.satisfied == false); assertTrue(e.getUnsatisfiedConditions().contains(startCondition)); } catch (IllegalServiceStateException e) { assertFalse(serviceFactory.isEnabled()); } assertSame(serviceName, serviceManager.getServiceName()); assertSame(serviceFactory, serviceManager.getServiceFactory()); assertSame(classLoader, serviceManager.getClassLoader()); if (serviceFactory.restartable) { assertSame(ServiceState.STOPPED, serviceManager.getState()); assertEquals(0, serviceManager.getStartTime()); assertNull(serviceManager.getService()); assertNotNull(serviceMonitor.registered); assertNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNull(serviceMonitor.running); assertNull(serviceMonitor.stopping); assertNull(serviceMonitor.waitingToStop); assertNull(serviceMonitor.stopError); assertNull(serviceMonitor.stopped); assertNull(serviceMonitor.unregistered); assertFalse(startCondition.initializeCalled); assertFalse(startCondition.isSatisfiedCalled); assertFalse(startCondition.destroyCalled); assertFalse(stopCondition.initializeCalled); assertFalse(stopCondition.isSatisfiedCalled); assertFalse(stopCondition.destroyCalled); } else if (!serviceFactory.isEnabled()) { assertSame(ServiceState.STOPPED, serviceManager.getState()); assertEquals(0, serviceManager.getStartTime()); assertNull(serviceManager.getService()); assertNull(serviceMonitor.registered); assertNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNull(serviceMonitor.running); assertNull(serviceMonitor.stopping); assertNull(serviceMonitor.stopError); assertNull(serviceMonitor.stopped); assertNull(serviceMonitor.unregistered); assertFalse(startCondition.initializeCalled); assertFalse(startCondition.isSatisfiedCalled); assertFalse(startCondition.destroyCalled); assertFalse(stopCondition.initializeCalled); assertFalse(stopCondition.isSatisfiedCalled); assertFalse(stopCondition.destroyCalled); } else if (serviceFactory.throwExceptionFromCreate != true && startCondition.satisfied == true) { assertSame(ServiceState.RUNNING, serviceManager.getState()); assertSame(SERVICE, serviceManager.getService()); assertTrue(serviceManager.getStartTime() > now); assertNotNull(serviceMonitor.registered); assertNotNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNotNull(serviceMonitor.running); assertNull(serviceMonitor.stopping); assertNull(serviceMonitor.stopError); assertNull(serviceMonitor.stopped); assertNull(serviceMonitor.unregistered); assertEquals(serviceMonitor.registered.getEventId() + 1, serviceMonitor.starting.getEventId()); assertEquals(serviceMonitor.registered.getEventId() + 2, serviceMonitor.running.getEventId()); assertTrue(startCondition.initializeCalled); assertTrue(startCondition.isSatisfiedCalled); assertFalse(startCondition.destroyCalled); assertFalse(stopCondition.initializeCalled); assertFalse(stopCondition.isSatisfiedCalled); assertFalse(stopCondition.destroyCalled); } else { assertSame(ServiceState.STOPPED, serviceManager.getState()); assertEquals(0, serviceManager.getStartTime()); assertNull(serviceManager.getService()); assertNotNull(serviceMonitor.registered); assertNotNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNull(serviceMonitor.running); assertNotNull(serviceMonitor.stopping); assertNull(serviceMonitor.stopError); assertNotNull(serviceMonitor.stopped); assertNotNull(serviceMonitor.unregistered); assertEquals(serviceMonitor.registered.getEventId() + 1, serviceMonitor.starting.getEventId()); assertEquals(serviceMonitor.registered.getEventId() + 2, serviceMonitor.stopping.getEventId()); assertEquals(serviceMonitor.registered.getEventId() + 3, serviceMonitor.stopped.getEventId()); assertEquals(serviceMonitor.registered.getEventId() + 4, serviceMonitor.unregistered.getEventId()); assertTrue(startCondition.initializeCalled); assertTrue(startCondition.isSatisfiedCalled); assertTrue(startCondition.destroyCalled); assertFalse(stopCondition.initializeCalled); assertFalse(stopCondition.isSatisfiedCalled); assertFalse(stopCondition.destroyCalled); } }
assertEquals(serviceName, e.getServiceName());
private void startException(StartStrategy startStrategy, boolean recursive) throws Exception { serviceFactory.throwExceptionFromCreate = true; try { start(recursive, startStrategy); } catch (MockCreateException e) { assertTrue(startStrategy == StartStrategies.SYNCHRONOUS || startStrategy == StartStrategies.BLOCK); assertEquals(serviceFactory.createException, e); } catch (UnregisterServiceException e) { assertEquals(StartStrategies.UNREGISTER, startStrategy); assertSame(serviceFactory.createException, e.getCause()); } stop(StopStrategies.SYNCHRONOUS); }
} catch (IllegalServiceStateException excpected) {
} catch (IllegalServiceStateException e) {
private void startFromStopping(StartStrategy startStrategy) throws Exception { start(false, StartStrategies.ASYNCHRONOUS); stopCondition.satisfied = false; stop(StopStrategies.ASYNCHRONOUS); try { serviceManager.start(false, startStrategy); fail("Should have thrown an IllegalServiceStateException since start on a stopping service is an error"); } catch (IllegalServiceStateException excpected) { // expected } stopCondition.satisfied = true; stop(StopStrategies.ASYNCHRONOUS); }
assertEquals(serviceName, e.getServiceName());
private void startFromStopping(StartStrategy startStrategy) throws Exception { start(false, StartStrategies.ASYNCHRONOUS); stopCondition.satisfied = false; stop(StopStrategies.ASYNCHRONOUS); try { serviceManager.start(false, startStrategy); fail("Should have thrown an IllegalServiceStateException since start on a stopping service is an error"); } catch (IllegalServiceStateException excpected) { // expected } stopCondition.satisfied = true; stop(StopStrategies.ASYNCHRONOUS); }
assertEquals(serviceName, e.getServiceName());
private void startStopsException(StartStrategy startStrategy, StopStrategy stopStrategy) throws Exception { serviceFactory.throwExceptionFromCreate = true; serviceFactory.throwExceptionFromDestroy = true; try { start(false, startStrategy); } catch (MockCreateException e) { assertTrue(startStrategy == StartStrategies.SYNCHRONOUS || startStrategy == StartStrategies.BLOCK); assertEquals(serviceFactory.createException, e); } catch (UnregisterServiceException e) { assertEquals(StartStrategies.UNREGISTER, startStrategy); assertSame(serviceFactory.createException, e.getCause()); } stop(stopStrategy); }
assertEquals(serviceName, cause.getServiceName());
private void startWaiting(StartStrategy startStrategy, boolean recursive) throws Exception { startCondition.satisfied = false; try { start(recursive, startStrategy); } catch (UnsatisfiedConditionsException e) { assertTrue(startStrategy == StartStrategies.SYNCHRONOUS); assertTrue(e.getUnsatisfiedConditions().contains(startCondition)); } catch (UnregisterServiceException e) { assertEquals(StartStrategies.UNREGISTER, startStrategy); UnsatisfiedConditionsException cause = (UnsatisfiedConditionsException) e.getCause(); assertTrue(cause.getUnsatisfiedConditions().contains(startCondition)); } stop(StopStrategies.SYNCHRONOUS); }
assertEquals(serviceName, cause.getServiceName());
private void startWaitingStart(StartStrategy startStrategy, boolean recursive) throws Exception { startCondition.satisfied = recursive; try { start(recursive, startStrategy); } catch (UnsatisfiedConditionsException e) { assertTrue(startStrategy == StartStrategies.SYNCHRONOUS); assertTrue(e.getUnsatisfiedConditions().contains(startCondition)); } catch (UnregisterServiceException e) { assertEquals(StartStrategies.UNREGISTER, startStrategy); UnsatisfiedConditionsException cause = (UnsatisfiedConditionsException) e.getCause(); assertTrue(cause.getUnsatisfiedConditions().contains(startCondition)); } try { start(recursive, startStrategy); } catch (UnsatisfiedConditionsException e) { assertTrue(startStrategy == StartStrategies.SYNCHRONOUS); assertTrue(e.getUnsatisfiedConditions().contains(startCondition)); } catch (UnregisterServiceException e) { assertEquals(StartStrategies.UNREGISTER, startStrategy); UnsatisfiedConditionsException cause = (UnsatisfiedConditionsException) e.getCause(); assertTrue(cause.getUnsatisfiedConditions().contains(startCondition)); } startCondition.satisfied = true; start(recursive, startStrategy); start(recursive, startStrategy); stop(StopStrategies.SYNCHRONOUS); }
assertEquals(serviceName, cause.getServiceName());
private void stop(StopStrategy stopStrategy) throws Exception { serviceMonitor.reset(); startCondition.reset(); stopCondition.reset(); kernel.reset(); ServiceState initialState = serviceManager.getState(); serviceManager.stop(stopStrategy); assertSame(serviceName, serviceManager.getServiceName()); assertSame(serviceFactory, serviceManager.getServiceFactory()); assertSame(classLoader, serviceManager.getClassLoader()); // these events should never fire in response to start assertNull(serviceMonitor.registered); assertNull(serviceMonitor.starting); assertNull(serviceMonitor.waitingToStart); assertNull(serviceMonitor.startError); assertNull(serviceMonitor.running); if (initialState == ServiceState.STOPPED) { // // We were alredy stopped so nothing should have happened // assertEquals(0, serviceManager.getStartTime()); assertNull(serviceManager.getService()); assertSame(ServiceState.STOPPED, serviceManager.getState()); assertNull(serviceMonitor.stopping); assertNull(serviceMonitor.waitingToStop); assertNull(serviceMonitor.stopError); assertNull(serviceMonitor.stopped); assertNull(serviceMonitor.unregistered); // start condition methods assertFalse(startCondition.initializeCalled); assertFalse(startCondition.isSatisfiedCalled); assertFalse(startCondition.destroyCalled); // stop condition methods assertFalse(stopCondition.initializeCalled); assertFalse(stopCondition.isSatisfiedCalled); assertFalse(stopCondition.destroyCalled); } else if (!stopCondition.satisfied && stopStrategy != StopStrategies.FORCE) { // // waiting to stop // assertSame(ServiceState.STOPPING, serviceManager.getState()); assertTrue(serviceManager.getStartTime() > 0); assertSame(SERVICE, serviceManager.getService()); // verify expected events fired if (initialState != ServiceState.STOPPING) { assertNotNull(serviceMonitor.stopping); } assertNotNull(serviceMonitor.waitingToStop); assertNull(serviceMonitor.stopError); assertNull(serviceMonitor.stopped); assertNull(serviceMonitor.unregistered); // verify events fired in the correct order if (initialState != ServiceState.STOPPING) { assertEquals(serviceMonitor.stopping.getEventId() + 1, serviceMonitor.waitingToStop.getEventId()); } // our condition should be in the unsatisfied condition list assertNotNull(serviceMonitor.waitingToStop.getUnsatisfiedConditions()); assertTrue(serviceMonitor.waitingToStop.getUnsatisfiedConditions().contains(stopCondition)); // start condition methods assertFalse(startCondition.initializeCalled); assertFalse(startCondition.isSatisfiedCalled); assertFalse(startCondition.destroyCalled); // stop condition methods if (initialState == ServiceState.RUNNING) { assertTrue(stopCondition.initializeCalled); } else { assertFalse(stopCondition.initializeCalled); } assertTrue(stopCondition.isSatisfiedCalled); assertFalse(stopCondition.destroyCalled); } else if (!serviceFactory.throwExceptionFromDestroy) { // // Normal transition to STOPPED from either STARTING, RUNNING or STOPPING // assertSame(ServiceState.STOPPED, serviceManager.getState()); assertEquals(0, serviceManager.getStartTime()); assertNull(serviceManager.getService()); // verify expected events fired if (initialState != ServiceState.STOPPING) { assertNotNull(serviceMonitor.stopping); } assertNull(serviceMonitor.waitingToStop); if (stopStrategy == StopStrategies.FORCE) { assertNotNull(serviceMonitor.stopError); ForcedStopException cause = (ForcedStopException) serviceMonitor.stopError.getCause(); assertTrue(cause.getUnsatisfiedConditions().contains(stopCondition)); } else { assertNull(serviceMonitor.stopError); } assertNotNull(serviceMonitor.stopped); assertNull(serviceMonitor.unregistered); // verify events fired in the correct order if (stopStrategy == StopStrategies.FORCE) { assertEquals(serviceMonitor.stopping.getEventId() + 1, serviceMonitor.stopError.getEventId()); assertEquals(serviceMonitor.stopping.getEventId() + 2, serviceMonitor.stopped.getEventId()); } else if (initialState != ServiceState.STOPPING) { assertEquals(serviceMonitor.stopping.getEventId() + 1, serviceMonitor.stopped.getEventId()); } // start condition methods assertFalse(startCondition.initializeCalled); assertFalse(startCondition.isSatisfiedCalled); assertTrue(startCondition.destroyCalled); // stop condition methods if (initialState == ServiceState.STOPPING) { assertFalse(stopCondition.initializeCalled); assertTrue(stopCondition.isSatisfiedCalled); assertTrue(stopCondition.destroyCalled); } else { assertTrue(stopCondition.initializeCalled); assertTrue(stopCondition.isSatisfiedCalled); assertTrue(stopCondition.destroyCalled); } } else { // // Throw an exception from the destroy method // assertEquals(0, serviceManager.getStartTime()); assertNull(serviceManager.getService()); assertSame(ServiceState.STOPPED, serviceManager.getState()); // verify expected events fired if (initialState != ServiceState.STOPPING) { assertNotNull(serviceMonitor.stopping); } assertNull(serviceMonitor.waitingToStop); assertNotNull(serviceMonitor.stopError); assertNotNull(serviceMonitor.stopped); assertNull(serviceMonitor.unregistered); // verify events fired in the correct order if (initialState != ServiceState.STOPPING) { assertEquals(serviceMonitor.stopping.getEventId() + 1, serviceMonitor.stopError.getEventId()); assertEquals(serviceMonitor.stopping.getEventId() + 2, serviceMonitor.stopped.getEventId()); } else { assertEquals(serviceMonitor.stopError.getEventId() + 1, serviceMonitor.stopped.getEventId()); } // verify that the exception is in the reson field assertSame(serviceFactory.destroyException, serviceMonitor.stopError.getCause()); // start condition methods assertFalse(startCondition.initializeCalled); assertFalse(startCondition.isSatisfiedCalled); assertTrue(startCondition.destroyCalled); // stop condition methods if (initialState == ServiceState.RUNNING) { assertTrue(stopCondition.initializeCalled); } else { assertFalse(stopCondition.initializeCalled); } assertTrue(stopCondition.isSatisfiedCalled); assertTrue(stopCondition.destroyCalled); } }
assertEquals(serviceName, e.getServiceName());
public void waitingStop(StopStrategy stopStrategy) throws Exception { start(false, StartStrategies.SYNCHRONOUS); stopCondition.satisfied = false; try { stop(stopStrategy); } catch (UnsatisfiedConditionsException e) { assertTrue(stopStrategy == StopStrategies.SYNCHRONOUS); assertTrue(e.getUnsatisfiedConditions().contains(stopCondition)); } try { stop(stopStrategy); } catch (UnsatisfiedConditionsException e) { assertTrue(stopStrategy == StopStrategies.SYNCHRONOUS); assertTrue(e.getUnsatisfiedConditions().contains(stopCondition)); } stopCondition.satisfied = true; stop(stopStrategy); }
.println(" [\"String\", \"Number\", \"Percentage\", \"Percentage\", \"LocalizedNumber\"]);");
.println(" [\"String\", \"Number\", \"Percentage\", \"Percentage\", \"FormattedNumber\"]);");
private void generateOverview(PackageData packageData) throws IOException { Iterator iter; String filename; if (packageData == null) { filename = "frame-summary.html"; } else { filename = "frame-summary-" + packageData.getName() + ".html"; } File file = new File(destinationDir, filename); PrintStream out = null; try { out = new PrintStream(new FileOutputStream(file)); out.println("<html>"); out.println("<head>"); out.println("<title>Coverage Report</title>"); out .println("<link title=\"Style\" type=\"text/css\" rel=\"stylesheet\" href=\"css/main.css\" />"); out .println("<link title=\"Style\" type=\"text/css\" rel=\"stylesheet\" href=\"css/sortabletable.css\" />"); out .println("<script type=\"text/javascript\" src=\"js/popup.js\"></script>"); out .println("<script type=\"text/javascript\" src=\"js/sortabletable.js\"></script>"); out .println("<script type=\"text/javascript\" src=\"js/customsorttypes.js\"></script>"); out.println("</head>"); out.println("<body>"); out.print("<h5>Coverage Report - "); out.print(packageData == null ? "All Packages" : generatePackageName(packageData)); out.println("</h5>"); out.println("<p>"); out.println("<table class=\"report\" id=\"packageResults\">"); out.println("<thead>"); out.println("<tr>"); out.println(" <td class=\"heading\">Package</td>"); out.println(" <td class=\"heading\"># Classes</td>"); out.println(generateCommonTableColumns()); out.println("</tr>"); out.println("</thead>"); out.println("<tbody>"); SortedSet packages; if (packageData == null) { // Output a summary line for all packages out.println(generateTableRowForTotal()); // Get packages packages = projectData.getPackages(); } else { // Get subpackages packages = projectData.getSubPackages(packageData.getName()); } // Output a line for each package or subpackage iter = packages.iterator(); while (iter.hasNext()) { PackageData subPackageData = (PackageData)iter.next(); out.println(generateTableRowForPackage(subPackageData)); } out.println("</tbody>"); out.println("</table>"); out.println("<script type=\"text/javascript\">"); out .println("var packageTable = new SortableTable(document.getElementById(\"packageResults\"),"); out .println(" [\"String\", \"Number\", \"Percentage\", \"Percentage\", \"LocalizedNumber\"]);"); out.println("packageTable.sort(0);"); out.println("</script>"); out.println("</p>"); // Get the list of source files in this package Collection sourceFiles; if (packageData == null) { PackageData defaultPackage = (PackageData)projectData .getChild(""); if (defaultPackage != null) { sourceFiles = defaultPackage.getSourceFiles(); } else { sourceFiles = new TreeSet(); } } else { sourceFiles = packageData.getSourceFiles(); } // Output a line for each class if (sourceFiles.size() > 0) { out.println("<p>"); out.println("<table class=\"report\" id=\"classResults\">"); out.println(generateTableHeaderForClasses()); out.println("<tbody>"); iter = sourceFiles.iterator(); while (iter.hasNext()) { SourceFileData sourceFileData = (SourceFileData)iter .next(); out .println(generateTableRowForSourceFile(sourceFileData)); } out.println("</tbody>"); out.println("</table>"); out.println("<script type=\"text/javascript\">"); out .println("var classTable = new SortableTable(document.getElementById(\"classResults\"),"); out .println(" [\"String\", \"Percentage\", \"Percentage\", \"LocalizedNumber\"]);"); out.println("classTable.sort(0);"); out.println("</script>"); out.println("</p>"); } out.println("<div class=\"footer\">"); out .println("Report generated by <a href=\"http://cobertura.sourceforge.net/\" target=\"_top\">Cobertura</a>."); out.println("</div>"); out.println("</body>"); out.println("</html>"); } finally { if (out != null) { out.close(); } } }
.println(" [\"String\", \"Percentage\", \"Percentage\", \"LocalizedNumber\"]);");
.println(" [\"String\", \"Percentage\", \"Percentage\", \"FormattedNumber\"]);");
private void generateOverview(PackageData packageData) throws IOException { Iterator iter; String filename; if (packageData == null) { filename = "frame-summary.html"; } else { filename = "frame-summary-" + packageData.getName() + ".html"; } File file = new File(destinationDir, filename); PrintStream out = null; try { out = new PrintStream(new FileOutputStream(file)); out.println("<html>"); out.println("<head>"); out.println("<title>Coverage Report</title>"); out .println("<link title=\"Style\" type=\"text/css\" rel=\"stylesheet\" href=\"css/main.css\" />"); out .println("<link title=\"Style\" type=\"text/css\" rel=\"stylesheet\" href=\"css/sortabletable.css\" />"); out .println("<script type=\"text/javascript\" src=\"js/popup.js\"></script>"); out .println("<script type=\"text/javascript\" src=\"js/sortabletable.js\"></script>"); out .println("<script type=\"text/javascript\" src=\"js/customsorttypes.js\"></script>"); out.println("</head>"); out.println("<body>"); out.print("<h5>Coverage Report - "); out.print(packageData == null ? "All Packages" : generatePackageName(packageData)); out.println("</h5>"); out.println("<p>"); out.println("<table class=\"report\" id=\"packageResults\">"); out.println("<thead>"); out.println("<tr>"); out.println(" <td class=\"heading\">Package</td>"); out.println(" <td class=\"heading\"># Classes</td>"); out.println(generateCommonTableColumns()); out.println("</tr>"); out.println("</thead>"); out.println("<tbody>"); SortedSet packages; if (packageData == null) { // Output a summary line for all packages out.println(generateTableRowForTotal()); // Get packages packages = projectData.getPackages(); } else { // Get subpackages packages = projectData.getSubPackages(packageData.getName()); } // Output a line for each package or subpackage iter = packages.iterator(); while (iter.hasNext()) { PackageData subPackageData = (PackageData)iter.next(); out.println(generateTableRowForPackage(subPackageData)); } out.println("</tbody>"); out.println("</table>"); out.println("<script type=\"text/javascript\">"); out .println("var packageTable = new SortableTable(document.getElementById(\"packageResults\"),"); out .println(" [\"String\", \"Number\", \"Percentage\", \"Percentage\", \"LocalizedNumber\"]);"); out.println("packageTable.sort(0);"); out.println("</script>"); out.println("</p>"); // Get the list of source files in this package Collection sourceFiles; if (packageData == null) { PackageData defaultPackage = (PackageData)projectData .getChild(""); if (defaultPackage != null) { sourceFiles = defaultPackage.getSourceFiles(); } else { sourceFiles = new TreeSet(); } } else { sourceFiles = packageData.getSourceFiles(); } // Output a line for each class if (sourceFiles.size() > 0) { out.println("<p>"); out.println("<table class=\"report\" id=\"classResults\">"); out.println(generateTableHeaderForClasses()); out.println("<tbody>"); iter = sourceFiles.iterator(); while (iter.hasNext()) { SourceFileData sourceFileData = (SourceFileData)iter .next(); out .println(generateTableRowForSourceFile(sourceFileData)); } out.println("</tbody>"); out.println("</table>"); out.println("<script type=\"text/javascript\">"); out .println("var classTable = new SortableTable(document.getElementById(\"classResults\"),"); out .println(" [\"String\", \"Percentage\", \"Percentage\", \"LocalizedNumber\"]);"); out.println("classTable.sort(0);"); out.println("</script>"); out.println("</p>"); } out.println("<div class=\"footer\">"); out .println("Report generated by <a href=\"http://cobertura.sourceforge.net/\" target=\"_top\">Cobertura</a>."); out.println("</div>"); out.println("</body>"); out.println("</html>"); } finally { if (out != null) { out.close(); } } }
+ "<td class=\"value\">" + getDoubleValue(ccn) + "</td>";
+ "<td class=\"value\"><span class=\"hidden\">" + ccn + ";</span>" + getDoubleValue(ccn) + "</td>";
private static String generateTableColumnsFromData(double lineCoverage, double branchCoverage, double ccn) { String lineCoverageCell = (lineCoverage == -1) ? generateNAPercent() : generatePercentResult(lineCoverage); String branchCoverageCell = (branchCoverage == -1) ? generateNAPercent() : generatePercentResult(branchCoverage); return "<td class=\"value\">" + lineCoverageCell + "</td>" + "<td class=\"value\">" + branchCoverageCell + "</td>" + "<td class=\"value\">" + getDoubleValue(ccn) + "</td>"; }
g2d.setClip(vButtonShape);
if(!Spark.isMac()){ g2d.setClip(vButtonShape); }
public void paint(Graphics g, JComponent c) { Graphics2D g2d = (Graphics2D)g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Insets vInsets = c.getInsets(); int w = c.getWidth() - (vInsets.left + vInsets.right); int h = c.getHeight() - (vInsets.top + vInsets.bottom); int x = vInsets.left; int y = vInsets.top; int arc = 8; Shape vButtonShape = new RoundRectangle2D.Double((double)x, (double)y, (double)w, (double)h, (double)arc, (double)arc); Shape vOldClip = g.getClip(); g2d.setClip(vButtonShape); g2d.setColor(backgroundColor2); g2d.fillRect(x, y, w, h); g2d.setClip(vOldClip); GradientPaint vPaint = new GradientPaint(x, y, borderColor, x, y + h, borderHighlight); g2d.setPaint(vPaint); // Handle custom actions. if (placement == JTabbedPane.TOP) { if (selected) { g2d.setColor(Color.lightGray); g2d.drawRoundRect(x, y, w, h, arc, arc); } g2d.clipRect(x, y, w + 1, h - arc / 4); g2d.setColor(borderColorAlpha1); g2d.setClip(vOldClip); g2d.setColor(borderColorAlpha2); g2d.setColor(backgroundColor2); g2d.fillRect(x, h - 5, w, h); } else { // Make straight line. g2d.setColor(backgroundColor2); g2d.fillRect(x, y, w, 4); } if (selected) { } else if (!hideBorder) { // Draw border on right side. g2d.setColor(Color.lightGray); g2d.drawLine(w - 1, 4, w - 1, h - 4); } }
public void fileTransferRequest(FileTransferRequest request) { if (fireTransferListeners(request)) { return; } String requestor = request.getRequestor(); String bareJID = StringUtils.parseBareAddress(requestor); ContactItem contactItem = contactList.getContactItemByJID(bareJID); ChatRoom chatRoom; if (contactItem != null) { chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, contactItem.getNickname(), contactItem.getNickname()); } else { chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, bareJID, bareJID); } TranscriptWindow transcriptWindow = chatRoom.getTranscriptWindow(); StyledDocument doc = (StyledDocument)transcriptWindow.getDocument(); Style style = doc.addStyle("StyleName", null); final ReceiveMessage receivingMessageUI = new ReceiveMessage(); receivingMessageUI.acceptFileTransfer(request); chatRoom.addClosingListener(new ChatRoomClosingListener() { public void closing() { receivingMessageUI.cancelTransfer();
public void fileTransferRequest(final FileTransferRequest request) { SwingUtilities.invokeLater(new Runnable() { public void run() { handleTransferRequest(request, contactList);
private SparkTransferManager() { boolean enabled = Enterprise.containsFeature(Enterprise.FILE_TRANSFER_FEATURE); if (!enabled) { return; } // Register Preferences PreferenceManager prefManager = SparkManager.getPreferenceManager(); prefManager.addPreference(new FileTransferPreference()); final JMenu actionsMenu = SparkManager.getMainWindow().getMenuByName("Actions"); JMenuItem downloadsMenu = new JMenuItem("", SparkRes.getImageIcon(SparkRes.DOWNLOAD_16x16)); ResourceUtils.resButton(downloadsMenu, "&View Downloads"); actionsMenu.add(downloadsMenu); downloadsMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Downloads downloads = Downloads.getInstance(); downloads.showDownloadsDirectory(); } }); // Create the file transfer manager transferManager = new FileTransferManager(SparkManager.getConnection()); final ContactList contactList = SparkManager.getWorkspace().getContactList(); // Create the listener transferManager.addFileTransferListener(new org.jivesoftware.smackx.filetransfer.FileTransferListener() { public void fileTransferRequest(FileTransferRequest request) { // Check if a listener handled this request if (fireTransferListeners(request)) { return; } String requestor = request.getRequestor(); String bareJID = StringUtils.parseBareAddress(requestor); ContactItem contactItem = contactList.getContactItemByJID(bareJID); ChatRoom chatRoom; if (contactItem != null) { chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, contactItem.getNickname(), contactItem.getNickname()); } else { chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, bareJID, bareJID); } TranscriptWindow transcriptWindow = chatRoom.getTranscriptWindow(); StyledDocument doc = (StyledDocument)transcriptWindow.getDocument(); // The image must first be wrapped in a style Style style = doc.addStyle("StyleName", null); final ReceiveMessage receivingMessageUI = new ReceiveMessage(); receivingMessageUI.acceptFileTransfer(request); chatRoom.addClosingListener(new ChatRoomClosingListener() { public void closing() { receivingMessageUI.cancelTransfer(); } }); StyleConstants.setComponent(style, receivingMessageUI); // Insert the image at the end of the text try { doc.insertString(doc.getLength(), "ignored text", style); doc.insertString(doc.getLength(), "\n", null); } catch (BadLocationException e) { Log.error(e); } chatRoom.scrollToBottom(); SparkManager.getChatManager().getChatContainer().fireNotifyOnMessage(chatRoom); } }); // Add Send File to Chat Room addSendFileButton(); contactList.addFileDropListener(new FileDropListener() { public void filesDropped(Collection files, Component component) { if (component instanceof ContactItem) { ContactItem item = (ContactItem)component; ChatRoom chatRoom = null; Iterator iter = files.iterator(); while (iter.hasNext()) { chatRoom = sendFile((File)iter.next(), item.getFullJID()); } if (chatRoom != null) { SparkManager.getChatManager().getChatContainer().activateChatRoom(chatRoom); } } } }); if (defaultDirectory == null) { defaultDirectory = new File(System.getProperty("user.home")); } addPresenceListener(); // Add View Downloads to Command Panel StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); JPanel commandPanel = statusBar.getCommandPanel(); RolloverButton viewDownloads = new RolloverButton(SparkRes.getImageIcon(SparkRes.DOWNLOAD_16x16)); viewDownloads.setToolTipText("View Downloads"); commandPanel.add(viewDownloads); viewDownloads.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Downloads downloads = Downloads.getInstance(); downloads.showDownloadsDirectory(); } }); }
StyleConstants.setComponent(style, receivingMessageUI); try { doc.insertString(doc.getLength(), "ignored text", style); doc.insertString(doc.getLength(), "\n", null); } catch (BadLocationException e) { Log.error(e); } chatRoom.scrollToBottom(); SparkManager.getChatManager().getChatContainer().fireNotifyOnMessage(chatRoom);
private SparkTransferManager() { boolean enabled = Enterprise.containsFeature(Enterprise.FILE_TRANSFER_FEATURE); if (!enabled) { return; } // Register Preferences PreferenceManager prefManager = SparkManager.getPreferenceManager(); prefManager.addPreference(new FileTransferPreference()); final JMenu actionsMenu = SparkManager.getMainWindow().getMenuByName("Actions"); JMenuItem downloadsMenu = new JMenuItem("", SparkRes.getImageIcon(SparkRes.DOWNLOAD_16x16)); ResourceUtils.resButton(downloadsMenu, "&View Downloads"); actionsMenu.add(downloadsMenu); downloadsMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Downloads downloads = Downloads.getInstance(); downloads.showDownloadsDirectory(); } }); // Create the file transfer manager transferManager = new FileTransferManager(SparkManager.getConnection()); final ContactList contactList = SparkManager.getWorkspace().getContactList(); // Create the listener transferManager.addFileTransferListener(new org.jivesoftware.smackx.filetransfer.FileTransferListener() { public void fileTransferRequest(FileTransferRequest request) { // Check if a listener handled this request if (fireTransferListeners(request)) { return; } String requestor = request.getRequestor(); String bareJID = StringUtils.parseBareAddress(requestor); ContactItem contactItem = contactList.getContactItemByJID(bareJID); ChatRoom chatRoom; if (contactItem != null) { chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, contactItem.getNickname(), contactItem.getNickname()); } else { chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, bareJID, bareJID); } TranscriptWindow transcriptWindow = chatRoom.getTranscriptWindow(); StyledDocument doc = (StyledDocument)transcriptWindow.getDocument(); // The image must first be wrapped in a style Style style = doc.addStyle("StyleName", null); final ReceiveMessage receivingMessageUI = new ReceiveMessage(); receivingMessageUI.acceptFileTransfer(request); chatRoom.addClosingListener(new ChatRoomClosingListener() { public void closing() { receivingMessageUI.cancelTransfer(); } }); StyleConstants.setComponent(style, receivingMessageUI); // Insert the image at the end of the text try { doc.insertString(doc.getLength(), "ignored text", style); doc.insertString(doc.getLength(), "\n", null); } catch (BadLocationException e) { Log.error(e); } chatRoom.scrollToBottom(); SparkManager.getChatManager().getChatContainer().fireNotifyOnMessage(chatRoom); } }); // Add Send File to Chat Room addSendFileButton(); contactList.addFileDropListener(new FileDropListener() { public void filesDropped(Collection files, Component component) { if (component instanceof ContactItem) { ContactItem item = (ContactItem)component; ChatRoom chatRoom = null; Iterator iter = files.iterator(); while (iter.hasNext()) { chatRoom = sendFile((File)iter.next(), item.getFullJID()); } if (chatRoom != null) { SparkManager.getChatManager().getChatContainer().activateChatRoom(chatRoom); } } } }); if (defaultDirectory == null) { defaultDirectory = new File(System.getProperty("user.home")); } addPresenceListener(); // Add View Downloads to Command Panel StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); JPanel commandPanel = statusBar.getCommandPanel(); RolloverButton viewDownloads = new RolloverButton(SparkRes.getImageIcon(SparkRes.DOWNLOAD_16x16)); viewDownloads.setToolTipText("View Downloads"); commandPanel.add(viewDownloads); viewDownloads.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Downloads downloads = Downloads.getInstance(); downloads.showDownloadsDirectory(); } }); }
public void fileTransferRequest(FileTransferRequest request) { if (fireTransferListeners(request)) { return; } String requestor = request.getRequestor(); String bareJID = StringUtils.parseBareAddress(requestor); ContactItem contactItem = contactList.getContactItemByJID(bareJID); ChatRoom chatRoom; if (contactItem != null) { chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, contactItem.getNickname(), contactItem.getNickname()); } else { chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, bareJID, bareJID); } TranscriptWindow transcriptWindow = chatRoom.getTranscriptWindow(); StyledDocument doc = (StyledDocument)transcriptWindow.getDocument(); Style style = doc.addStyle("StyleName", null); final ReceiveMessage receivingMessageUI = new ReceiveMessage(); receivingMessageUI.acceptFileTransfer(request); chatRoom.addClosingListener(new ChatRoomClosingListener() { public void closing() { receivingMessageUI.cancelTransfer();
public void fileTransferRequest(final FileTransferRequest request) { SwingUtilities.invokeLater(new Runnable() { public void run() { handleTransferRequest(request, contactList);
public void fileTransferRequest(FileTransferRequest request) { // Check if a listener handled this request if (fireTransferListeners(request)) { return; } String requestor = request.getRequestor(); String bareJID = StringUtils.parseBareAddress(requestor); ContactItem contactItem = contactList.getContactItemByJID(bareJID); ChatRoom chatRoom; if (contactItem != null) { chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, contactItem.getNickname(), contactItem.getNickname()); } else { chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, bareJID, bareJID); } TranscriptWindow transcriptWindow = chatRoom.getTranscriptWindow(); StyledDocument doc = (StyledDocument)transcriptWindow.getDocument(); // The image must first be wrapped in a style Style style = doc.addStyle("StyleName", null); final ReceiveMessage receivingMessageUI = new ReceiveMessage(); receivingMessageUI.acceptFileTransfer(request); chatRoom.addClosingListener(new ChatRoomClosingListener() { public void closing() { receivingMessageUI.cancelTransfer(); } }); StyleConstants.setComponent(style, receivingMessageUI); // Insert the image at the end of the text try { doc.insertString(doc.getLength(), "ignored text", style); doc.insertString(doc.getLength(), "\n", null); } catch (BadLocationException e) { Log.error(e); } chatRoom.scrollToBottom(); SparkManager.getChatManager().getChatContainer().fireNotifyOnMessage(chatRoom); }
StyleConstants.setComponent(style, receivingMessageUI); try { doc.insertString(doc.getLength(), "ignored text", style); doc.insertString(doc.getLength(), "\n", null); } catch (BadLocationException e) { Log.error(e); } chatRoom.scrollToBottom(); SparkManager.getChatManager().getChatContainer().fireNotifyOnMessage(chatRoom);
public void fileTransferRequest(FileTransferRequest request) { // Check if a listener handled this request if (fireTransferListeners(request)) { return; } String requestor = request.getRequestor(); String bareJID = StringUtils.parseBareAddress(requestor); ContactItem contactItem = contactList.getContactItemByJID(bareJID); ChatRoom chatRoom; if (contactItem != null) { chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, contactItem.getNickname(), contactItem.getNickname()); } else { chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, bareJID, bareJID); } TranscriptWindow transcriptWindow = chatRoom.getTranscriptWindow(); StyledDocument doc = (StyledDocument)transcriptWindow.getDocument(); // The image must first be wrapped in a style Style style = doc.addStyle("StyleName", null); final ReceiveMessage receivingMessageUI = new ReceiveMessage(); receivingMessageUI.acceptFileTransfer(request); chatRoom.addClosingListener(new ChatRoomClosingListener() { public void closing() { receivingMessageUI.cancelTransfer(); } }); StyleConstants.setComponent(style, receivingMessageUI); // Insert the image at the end of the text try { doc.insertString(doc.getLength(), "ignored text", style); doc.insertString(doc.getLength(), "\n", null); } catch (BadLocationException e) { Log.error(e); } chatRoom.scrollToBottom(); SparkManager.getChatManager().getChatContainer().fireNotifyOnMessage(chatRoom); }
public void actionPerformed(ActionEvent e) { SwingWorker worker = new SwingWorker() { public Object construct() { try { Thread.sleep(10); } catch (InterruptedException e1) { Log.error(e1); } return "delay"; } public void finished() { ChatRoomImpl roomImpl = (ChatRoomImpl)room; getFileChooser().setDialogTitle("Select File(s) to send"); getFileChooser().setMultiSelectionEnabled(true); int ok = getFileChooser().showOpenDialog(roomImpl); if (ok != JFileChooser.APPROVE_OPTION) { return; } File[] file = getFileChooser().getSelectedFiles(); if (file == null || file.length == 0) { return; } final int no = file.length; for (int i = 0; i < no; i++) { File sendFile = file[i]; if (sendFile.exists()) { defaultDirectory = sendFile.getParentFile(); sendFile(sendFile, roomImpl.getParticipantJID()); } } } }; worker.start();
public void actionPerformed(ActionEvent actionEvent) { sendScreenshot(sendScreenShotButton, room);
public void actionPerformed(ActionEvent e) { SwingWorker worker = new SwingWorker() { public Object construct() { try { Thread.sleep(10); } catch (InterruptedException e1) { Log.error(e1); } return "delay"; } public void finished() { ChatRoomImpl roomImpl = (ChatRoomImpl)room; getFileChooser().setDialogTitle("Select File(s) to send"); getFileChooser().setMultiSelectionEnabled(true); int ok = getFileChooser().showOpenDialog(roomImpl); if (ok != JFileChooser.APPROVE_OPTION) { return; } File[] file = getFileChooser().getSelectedFiles(); if (file == null || file.length == 0) { return; } final int no = file.length; for (int i = 0; i < no; i++) { File sendFile = file[i]; if (sendFile.exists()) { defaultDirectory = sendFile.getParentFile(); sendFile(sendFile, roomImpl.getParticipantJID()); } } } }; worker.start(); }
if (presence == null || presence.getType() == Presence.Type.unavailable) { if (transfer != null) { transfer.cancel();
if (presence != null) { String bareJID = StringUtils.parseBareAddress(presence.getFrom()); List list = (List)waitMap.get(bareJID); if (list != null) { Iterator iter = list.iterator(); ChatRoom room = null; while (iter.hasNext()) { File file = (File)iter.next(); room = sendFile(file, bareJID); } if (room != null) { Message message = new Message(); message.setBody("You have just been sent offline file(s)."); room.sendMessage(message); }
public void processPacket(Packet packet) { Presence presence = (Presence)packet; if (presence == null || presence.getType() == Presence.Type.unavailable) { if (transfer != null) { transfer.cancel(); } } }
waitMap.remove(bareJID);
public void processPacket(Packet packet) { Presence presence = (Presence)packet; if (presence == null || presence.getType() == Presence.Type.unavailable) { if (transfer != null) { transfer.cancel(); } } }
try { Robot robot = new Robot(); Rectangle area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); return robot.createScreenCapture(area); } catch (AWTException e) { Log.error(e); } return null; }
try { Thread.sleep(10); } catch (InterruptedException e1) { Log.error(e1); } return "delay"; }
public Object construct() { try { Robot robot = new Robot(); Rectangle area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); return robot.createScreenCapture(area); } catch (AWTException e) { Log.error(e); } return null; }
BufferedImage bufferedImage = (BufferedImage)get(); if (bufferedImage != null) { sendImage(bufferedImage, room); }
ChatRoomImpl roomImpl = (ChatRoomImpl)room;
public void finished() { BufferedImage bufferedImage = (BufferedImage)get(); if (bufferedImage != null) { sendImage(bufferedImage, room); } button.setEnabled(true); room.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); }
button.setEnabled(true); room.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); }
getFileChooser().setDialogTitle("Select File(s) to send"); getFileChooser().setMultiSelectionEnabled(true); int ok = getFileChooser().showOpenDialog(roomImpl); if (ok != JFileChooser.APPROVE_OPTION) { return; } File[] file = getFileChooser().getSelectedFiles(); if (file == null || file.length == 0) { return; } final int no = file.length; for (int i = 0; i < no; i++) { File sendFile = file[i]; if (sendFile.exists()) { defaultDirectory = sendFile.getParentFile(); sendFile(sendFile, roomImpl.getParticipantJID()); } } }
public void finished() { BufferedImage bufferedImage = (BufferedImage)get(); if (bufferedImage != null) { sendImage(bufferedImage, room); } button.setEnabled(true); room.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); }
indent -= indentRate;
if (indent > 0) indent--;
void decreaseIndentation() { indent -= indentRate; }
indent += indentRate;
indent++;
void increaseIndentation() { indent += indentRate; }
int i = 0; while (st.hasMoreElements()) {
for (int i=0; st.hasMoreElements(); i++) {
static private String[] tokenize(String list) { StringTokenizer st = new StringTokenizer(list," \t\n\f\r;,"); String[] tokens = new String[st.countTokens()]; int i = 0; while (st.hasMoreElements()) { tokens[i] = st.nextToken(); } return tokens; }
public SoftReferenceObjectPool(PoolableObjectFactory factory) {
public SoftReferenceObjectPool() {
public SoftReferenceObjectPool(PoolableObjectFactory factory) { _pool = new ArrayList(); _factory = factory; }
_factory = factory;
_factory = null;
public SoftReferenceObjectPool(PoolableObjectFactory factory) { _pool = new ArrayList(); _factory = factory; }
int getNumActive() throws UnsupportedOperationException;
int getNumActive(Object key) throws UnsupportedOperationException;
int getNumActive() throws UnsupportedOperationException;
int getNumIdle() throws UnsupportedOperationException;
int getNumIdle(Object key) throws UnsupportedOperationException;
int getNumIdle() throws UnsupportedOperationException;
public static ObjectPool adapt(final KeyedObjectPool keyedPool) throws IllegalArgumentException { return adapt(keyedPool, new Object());
public static PoolableObjectFactory adapt(final KeyedPoolableObjectFactory keyedFactory) throws IllegalArgumentException { return adapt(keyedFactory, new Object());
public static ObjectPool adapt(final KeyedObjectPool keyedPool) throws IllegalArgumentException { return adapt(keyedPool, new Object()); }
public static TimerTask checkMinIdle(final KeyedObjectPool keyedPool, final Object key, final int minIdle, final long period) throws IllegalArgumentException { if (keyedPool == null) {
public static TimerTask checkMinIdle(final ObjectPool pool, final int minIdle, final long period) throws IllegalArgumentException { if (pool == null) {
public static TimerTask checkMinIdle(final KeyedObjectPool keyedPool, final Object key, final int minIdle, final long period) throws IllegalArgumentException { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (key == null) { throw new IllegalArgumentException("key must not be null."); } if (minIdle < 0) { throw new IllegalArgumentException("minIdle must be non-negative."); } final TimerTask task = new KeyedObjectPoolMinIdleTimerTask(keyedPool, key, minIdle); getMinIdleTimer().schedule(task, 0L, period); return task; }
} if (key == null) { throw new IllegalArgumentException("key must not be null.");
public static TimerTask checkMinIdle(final KeyedObjectPool keyedPool, final Object key, final int minIdle, final long period) throws IllegalArgumentException { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (key == null) { throw new IllegalArgumentException("key must not be null."); } if (minIdle < 0) { throw new IllegalArgumentException("minIdle must be non-negative."); } final TimerTask task = new KeyedObjectPoolMinIdleTimerTask(keyedPool, key, minIdle); getMinIdleTimer().schedule(task, 0L, period); return task; }
final TimerTask task = new KeyedObjectPoolMinIdleTimerTask(keyedPool, key, minIdle);
final TimerTask task = new ObjectPoolMinIdleTimerTask(pool, minIdle);
public static TimerTask checkMinIdle(final KeyedObjectPool keyedPool, final Object key, final int minIdle, final long period) throws IllegalArgumentException { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (key == null) { throw new IllegalArgumentException("key must not be null."); } if (minIdle < 0) { throw new IllegalArgumentException("minIdle must be non-negative."); } final TimerTask task = new KeyedObjectPoolMinIdleTimerTask(keyedPool, key, minIdle); getMinIdleTimer().schedule(task, 0L, period); return task; }
public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory) { this(factory,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
public GenericKeyedObjectPool() { this(null,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory) { this(factory,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE); }
public GenericObjectPool(PoolableObjectFactory factory) { this(factory,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
public GenericObjectPool() { this(null,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);
public GenericObjectPool(PoolableObjectFactory factory) { this(factory,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE); }
public static KeyedObjectPool checkedPool(final KeyedObjectPool keyedPool, final Class type) { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null.");
public static ObjectPool checkedPool(final ObjectPool pool, final Class type) { if (pool == null) { throw new IllegalArgumentException("pool must not be null.");
public static KeyedObjectPool checkedPool(final KeyedObjectPool keyedPool, final Class type) { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (type == null) { throw new IllegalArgumentException("type must not be null."); } return new CheckedKeyedObjectPool(keyedPool, type); }
return new CheckedKeyedObjectPool(keyedPool, type);
return new CheckedObjectPool(pool, type);
public static KeyedObjectPool checkedPool(final KeyedObjectPool keyedPool, final Class type) { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (type == null) { throw new IllegalArgumentException("type must not be null."); } return new CheckedKeyedObjectPool(keyedPool, type); }
public static KeyedObjectPool erodingPool(final KeyedObjectPool keyedPool) { return erodingPool(keyedPool, 1f);
public static ObjectPool erodingPool(final ObjectPool pool) { return erodingPool(pool, 1f);
public static KeyedObjectPool erodingPool(final KeyedObjectPool keyedPool) { return erodingPool(keyedPool, 1f); }
public static void prefill(final KeyedObjectPool keyedPool, final Object key, final int count) throws Exception, IllegalArgumentException { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (key == null) { throw new IllegalArgumentException("key must not be null.");
public static void prefill(final ObjectPool pool, final int count) throws Exception, IllegalArgumentException { if (pool == null) { throw new IllegalArgumentException("pool must not be null.");
public static void prefill(final KeyedObjectPool keyedPool, final Object key, final int count) throws Exception, IllegalArgumentException { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (key == null) { throw new IllegalArgumentException("key must not be null."); } for (int i = 0; i < count; i++) { keyedPool.addObject(key); } }
keyedPool.addObject(key);
pool.addObject();
public static void prefill(final KeyedObjectPool keyedPool, final Object key, final int count) throws Exception, IllegalArgumentException { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (key == null) { throw new IllegalArgumentException("key must not be null."); } for (int i = 0; i < count; i++) { keyedPool.addObject(key); } }
public static KeyedObjectPool synchronizedPool(final KeyedObjectPool keyedPool) { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null.");
public static ObjectPool synchronizedPool(final ObjectPool pool) { if (pool == null) { throw new IllegalArgumentException("pool must not be null.");
public static KeyedObjectPool synchronizedPool(final KeyedObjectPool keyedPool) { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } assert !(keyedPool instanceof GenericKeyedObjectPool) : "GenericKeyedObjectPool is already thread-safe"; assert !(keyedPool instanceof StackKeyedObjectPool) : "StackKeyedObjectPool is already thread-safe"; assert !"org.apache.commons.pool.composite.CompositeKeyedObjectPool".equals(keyedPool.getClass().getName()) : "CompositeKeyedObjectPools are already thread-safe"; return new SynchronizedKeyedObjectPool(keyedPool); }
assert !(keyedPool instanceof GenericKeyedObjectPool) : "GenericKeyedObjectPool is already thread-safe"; assert !(keyedPool instanceof StackKeyedObjectPool) : "StackKeyedObjectPool is already thread-safe"; assert !"org.apache.commons.pool.composite.CompositeKeyedObjectPool".equals(keyedPool.getClass().getName()) : "CompositeKeyedObjectPools are already thread-safe"; return new SynchronizedKeyedObjectPool(keyedPool);
assert !(pool instanceof GenericObjectPool) : "GenericObjectPool is already thread-safe"; assert !(pool instanceof SoftReferenceObjectPool) : "SoftReferenceObjectPool is already thread-safe"; assert !(pool instanceof StackObjectPool) : "StackObjectPool is already thread-safe"; assert !"org.apache.commons.pool.composite.CompositeObjectPool".equals(pool.getClass().getName()) : "CompositeObjectPools are already thread-safe"; return new SynchronizedObjectPool(pool);
public static KeyedObjectPool synchronizedPool(final KeyedObjectPool keyedPool) { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } assert !(keyedPool instanceof GenericKeyedObjectPool) : "GenericKeyedObjectPool is already thread-safe"; assert !(keyedPool instanceof StackKeyedObjectPool) : "StackKeyedObjectPool is already thread-safe"; assert !"org.apache.commons.pool.composite.CompositeKeyedObjectPool".equals(keyedPool.getClass().getName()) : "CompositeKeyedObjectPools are already thread-safe"; return new SynchronizedKeyedObjectPool(keyedPool); }
public static KeyedPoolableObjectFactory synchronizedPoolableFactory(final KeyedPoolableObjectFactory keyedFactory) { return new SynchronizedKeyedPoolableObjectFactory(keyedFactory);
public static PoolableObjectFactory synchronizedPoolableFactory(final PoolableObjectFactory factory) { return new SynchronizedPoolableObjectFactory(factory);
public static KeyedPoolableObjectFactory synchronizedPoolableFactory(final KeyedPoolableObjectFactory keyedFactory) { return new SynchronizedKeyedPoolableObjectFactory(keyedFactory); }
assertNotNull(pool);
public void testVariousConstructors() throws Exception { { StackKeyedObjectPool pool = new StackKeyedObjectPool(); } { StackKeyedObjectPool pool = new StackKeyedObjectPool(10); } { StackKeyedObjectPool pool = new StackKeyedObjectPool(10,5); } { StackKeyedObjectPool pool = new StackKeyedObjectPool(null); } { StackKeyedObjectPool pool = new StackKeyedObjectPool(null,10); } { StackKeyedObjectPool pool = new StackKeyedObjectPool(null,10,5); } }
public StackKeyedObjectPool(KeyedPoolableObjectFactory factory, int max) { this(factory,max,DEFAULT_INIT_SLEEPING_CAPACITY);
public StackKeyedObjectPool() { this((KeyedPoolableObjectFactory)null,DEFAULT_MAX_SLEEPING,DEFAULT_INIT_SLEEPING_CAPACITY);
public StackKeyedObjectPool(KeyedPoolableObjectFactory factory, int max) { this(factory,max,DEFAULT_INIT_SLEEPING_CAPACITY); }
public int getNumActive(Object key) { try { return ((Integer)_activeCount.get(key)).intValue(); } catch(NoSuchElementException e) { return 0; } catch(NullPointerException e) { return 0; }
public int getNumActive() { return _totActive;
public int getNumActive(Object key) { try { return ((Integer)_activeCount.get(key)).intValue(); } catch(NoSuchElementException e) { return 0; } catch(NullPointerException e) { return 0; } }
public synchronized int getNumIdle(Object key) { try { return((Stack)(_pools.get(key))).size(); } catch(Exception e) { return 0; }
public int getNumIdle() { return _totIdle;
public synchronized int getNumIdle(Object key) { try { return((Stack)(_pools.get(key))).size(); } catch(Exception e) { return 0; } }
public synchronized Object borrowObject() throws Exception {
public Object borrowObject() throws Exception {
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ;
if (!_pool.isEmpty()) { synchronized(this) { try { _numActive++; pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; } if(null == pair) { _numActive--; notifyAll(); } }
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true;
try { _numActive++; Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } finally { if(null == pair) { synchronized(this) { _numActive--; notifyAll(); } } }
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj);
try { _numActive++; Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } finally { if(null == pair) { synchronized(this) { _numActive--; notifyAll(); } } }
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
try { if(_maxWait <= 0) { wait();
synchronized(this) { if (_pool.isEmpty()) { try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { } } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object");
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
wait(_maxWait);
continue;
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
} catch(InterruptedException e) { } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue;
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
_numActive++;
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
synchronized(this) { _numActive--; notifyAll(); }
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
if(_maxActive <= 0 || _numActive < _maxActive) {
if(_maxActive < 0 || _numActive < _maxActive) {
public Object borrowObject() throws Exception { long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; synchronized(this) { assertOpen(); // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { // allow new object to be created } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: // allow new object to be created break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } _numActive++; } // end synchronized // create new object when needed if(null == pair) { try { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } catch (Exception e) { // object cannot be created synchronized(this) { _numActive--; notifyAll(); } throw e; } } // activate & validate the object try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } return pair.value; } catch (Exception e) { // object cannot be activated or is invalid synchronized(this) { _numActive--; notifyAll(); } try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object, cause: " + e.getMessage()); } else { continue; // keep looping } } } }
public abstract Object makeObject();
public abstract Object makeObject() throws Exception;
public abstract Object makeObject();
assertNotNull(pool);
public void testVariousConstructors() throws Exception { { StackObjectPool pool = new StackObjectPool(); } { StackObjectPool pool = new StackObjectPool(10); } { StackObjectPool pool = new StackObjectPool(10,5); } { StackObjectPool pool = new StackObjectPool(null); } { StackObjectPool pool = new StackObjectPool(null,10); } { StackObjectPool pool = new StackObjectPool(null,10,5); } }
public StackObjectPool(PoolableObjectFactory factory) { this(factory,DEFAULT_MAX_SLEEPING,DEFAULT_INIT_SLEEPING_CAPACITY);
public StackObjectPool() { this((PoolableObjectFactory)null,DEFAULT_MAX_SLEEPING,DEFAULT_INIT_SLEEPING_CAPACITY);
public StackObjectPool(PoolableObjectFactory factory) { this(factory,DEFAULT_MAX_SLEEPING,DEFAULT_INIT_SLEEPING_CAPACITY); }
public MethodCall(final String name, final Object param) { this(name, Collections.singletonList(param));
public MethodCall(final String name) { this(name, null);
public MethodCall(final String name, final Object param) { this(name, Collections.singletonList(param)); }
public TestObjectPoolFactory(final String name) {
protected TestObjectPoolFactory(final String name) {
public TestObjectPoolFactory(final String name) { super(name); }