1 21 22 package org.apache.derbyTesting.unitTests.services; 23 24 import org.apache.derbyTesting.unitTests.harness.T_Generic; 25 import org.apache.derbyTesting.unitTests.harness.T_Fail; 26 27 import org.apache.derby.iapi.services.context.Context; 28 import org.apache.derby.iapi.services.context.ContextManager; 29 import org.apache.derby.iapi.services.monitor.Monitor; 30 import org.apache.derby.iapi.error.StandardException; 31 import org.apache.derby.iapi.services.daemon.*; 32 33 39 public class T_Serviceable implements Serviceable 40 { 41 protected int timesServiced; 44 45 protected final int timesRequeue; 47 protected final boolean onDemandOnly; 48 protected final boolean subscribed; 49 50 protected int clientNumber; 52 53 public T_Serviceable(int t) 55 { 56 timesServiced = 0; 57 timesRequeue = t; 58 onDemandOnly = false; subscribed = false; 60 clientNumber = -1; 61 } 62 63 public T_Serviceable(boolean onDemandOnly) 65 { 66 timesServiced = 0; 67 timesRequeue = 0; this.onDemandOnly = onDemandOnly; 69 subscribed = true; 70 } 71 72 protected void setClientNumber(int n) 73 { 74 clientNumber = n; 75 } 76 77 protected int getClientNumber() 78 { 79 return clientNumber; 80 } 81 82 85 public synchronized int performWork(ContextManager context) 86 { 87 context.toString(); 89 timesServiced++; 90 notifyAll(); 92 if (!subscribed && timesRequeue > timesServiced) 93 return Serviceable.REQUEUE; 94 else 95 return Serviceable.DONE; 96 } 97 98 public boolean serviceASAP() 99 { 100 return true; 101 } 102 103 104 public boolean serviceImmediately() 106 { 107 return false; 108 } 109 110 111 114 115 protected synchronized void t_wait(int n) 116 { 117 try 118 { 119 while (timesServiced < n) 120 wait(); 121 } 122 catch (InterruptedException ie) {} 123 } 124 125 protected synchronized void t_check(int n) throws T_Fail 126 { 127 if (timesServiced != n) 128 throw T_Fail.testFailMsg("Expect to be serviced " + n + " times, instead serviced " + timesServiced); 129 } 130 131 } 132 | Popular Tags |