Produced by Araxis Merge on 7/10/2017 1:01:43 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | C:\AraxisMergeCompare\Pri_un\IV-ehmp_cif\ImagingCommon\main\src\java\gov\va\med\asynchproxy | AsynchInvocationHandler.java | Thu Jun 29 17:22:59 2017 UTC |
| 2 | C:\AraxisMergeCompare\Pri_re\IV-ehmp_cif\ImagingCommon\main\src\java\gov\va\med\asynchproxy | AsynchInvocationHandler.java | Thu Jul 6 15:02:22 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 5 | 414 |
| Changed | 4 | 8 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | package go v.va.med.a synchproxy ; | |
| 2 | ||
| 3 | import jav a.lang.ref lect.Invoc ationHandl er; | |
| 4 | import jav a.lang.ref lect.Metho d; | |
| 5 | import jav a.util.con current.Ca llable; | |
| 6 | import jav a.util.con current.Co mpletionSe rvice; | |
| 7 | import jav a.util.con current.Ex ecutionExc eption; | |
| 8 | import jav a.util.con current.Ex ecutor; | |
| 9 | import jav a.util.con current.Ex ecutorComp letionServ ice; | |
| 10 | import jav a.util.con current.Ex ecutors; | |
| 11 | import jav a.util.con current.Fu ture; | |
| 12 | import jav a.util.con current.Th readFactor y; | |
| 13 | import jav a.util.con current.Ti meUnit; | |
| 14 | ||
| 15 | /** | |
| 16 | * | |
| 17 | * @author
|
|
| 18 | * | |
| 19 | * @param <I> | |
| 20 | */ | |
| 21 | public cla ss AsynchI nvocationH andler<I> | |
| 22 | implements Invocatio nHandler, Completion Service<Ge nericAsync hResult> | |
| 23 | { | |
| 24 | pr ivate stat ic final i nt DEFAULT _THREAD_CO UNT = 25; | |
| 25 | pr ivate I ta rget; | |
| 26 | pr ivate Comp letionServ ice<Generi cAsynchRes ult> compl etionServi ce; | |
| 27 | pr ivate Asyn chProxyLis tener list ener; | |
| 28 | ||
| 29 | pu blic Async hInvocatio nHandler(I target) | |
| 30 | { | |
| 31 | this (target, n ull, null) ; | |
| 32 | } | |
| 33 | ||
| 34 | pu blic Async hInvocatio nHandler(I target, A synchProxy Listener l istener) | |
| 35 | { | |
| 36 | this (target, n ull, liste ner); | |
| 37 | } | |
| 38 | ||
| 39 | pu blic Async hInvocatio nHandler(I target, E xecutor ex ecutor, As ynchProxyL istener li stener) | |
| 40 | { | |
| 41 | this .target = target; | |
| 42 | this .completio nService = new Execu torComplet ionService <GenericAs ynchResult >( | |
| 43 | execut or != null ? | |
| 44 | execut or : | |
| 45 | Execut ors.newFix edThreadPo ol(DEFAULT _THREAD_CO UNT, new A synchInvoc ationHandl erThreadFa ctory()) | |
| 46 | ); | |
| 47 | this .listener = listener ; | |
| 48 | ||
| 49 | if(l istener != null) | |
| 50 | { | |
| 51 | Thread listenerT hread = ne w Listener Notificati onThread(l istener); | |
| 52 | listen erThread.s etDaemon(t rue); | |
| 53 | listen erThread.s tart(); | |
| 54 | } | |
| 55 | } | |
| 56 | ||
| 57 | /* * | |
| 58 | * | |
| 59 | * @see java .lang.refl ect.Invoca tionHandle r#invoke(j ava.lang.O bject, jav a.lang.ref lect.Metho d, java.la ng.Object[ ]) | |
| 60 | * / | |
| 61 | pu blic Objec t invoke(O bject prox y, Method method, Ob ject[] arg s) | |
| 62 | th rows Throw able | |
| 63 | { | |
| 64 | Call able<Gener icAsynchRe sult> task = new Asy nchTask(me thod, args ); | |
| 65 | comp letionServ ice.submit (task); | |
| 66 | ||
| 67 | Clas s<?> retur nType = me thod.getRe turnType() ; | |
| 68 | ||
| 69 | // r eturn 0, f alse or nu ll dependi ng on the return typ e | |
| 70 | // t his result is meanin gless but always ret urning nul l will | |
| 71 | // r esult in a n NPE for primitive types. | |
| 72 | if(r eturnType == Charact er.class) return new Character ((char)0); | |
| 73 | if(r eturnType == Short.c lass) retu rn new Sho rt((short) 0); | |
| 74 | if(r eturnType == Integer .class) re turn new I nteger(0); | |
| 75 | if(r eturnType == Long.cl ass) retur n new Long (0); | |
| 76 | if(r eturnType == Boolean .class) re turn Boole an.FALSE; | |
| 77 | if(r eturnType == Float.c lass) retu rn new Flo at(0.0); | |
| 78 | if(r eturnType == Double. class) ret urn new Do uble(0.0); | |
| 79 | ||
| 80 | retu rn null; | |
| 81 | } | |
| 82 | ||
| 83 | ||
| 84 | /* * | |
| 85 | * @se e java.uti l.concurre nt.Complet ionService #submit(ja va.util.co ncurrent.C allable) | |
| 86 | */ | |
| 87 | public Future<Ge nericAsync hResult> s ubmit(Call able<Gener icAsynchRe sult> task ) | |
| 88 | { | |
| 89 | return c ompletionS ervice.sub mit(task); | |
| 90 | ||
| 91 | } | |
| 92 | ||
| 93 | /* * | |
| 94 | * @se e java.uti l.concurre nt.Complet ionService #submit(ja va.lang.Ru nnable, ja va.lang.Ob ject) | |
| 95 | */ | |
| 96 | public Future<Ge nericAsync hResult> s ubmit(Runn able task, GenericAs ynchResult result) | |
| 97 | { | |
| 98 | return c ompletionS ervice.sub mit(task, result); | |
| 99 | ||
| 100 | } | |
| 101 | ||
| 102 | /* * | |
| 103 | * @se e java.uti l.concurre nt.Complet ionService #poll() | |
| 104 | * / | |
| 105 | pu blic Futur e<GenericA synchResul t> poll() | |
| 106 | { | |
| 107 | retu rn complet ionService .poll(); | |
| 108 | } | |
| 109 | ||
| 110 | /* * | |
| 111 | * @see java .util.conc urrent.Com pletionSer vice#poll( long timeo ut, TimeUn it unit) | |
| 112 | * / | |
| 113 | pu blic Futur e<GenericA synchResul t> poll(lo ng timeout , TimeUnit unit) | |
| 114 | th rows Inter ruptedExce ption | |
| 115 | { | |
| 116 | retu rn complet ionService .poll(time out, unit) ; | |
| 117 | } | |
| 118 | ||
| 119 | /* * | |
| 120 | * @see java .util.conc urrent.Com pletionSer vice#take( ) | |
| 121 | * / | |
| 122 | pu blic Futur e<GenericA synchResul t> take() | |
| 123 | th rows Inter ruptedExce ption | |
| 124 | { | |
| 125 | retu rn complet ionService .take(); | |
| 126 | } | |
| 127 | ||
| 128 | /* * | |
| 129 | * | |
| 130 | * @author
|
|
| 131 | * | |
| 132 | * / | |
| 133 | cl ass Asynch Invocation HandlerThr eadFactory | |
| 134 | im plements T hreadFacto ry | |
| 135 | { | |
| 136 | priv ate int th readSerial Number = 0 ; | |
| 137 | priv ate String groupName = "Asynch Invocation Handler"; | |
| 138 | ||
| 139 | priv ate synchr onized int getThread SerialNumb er() | |
| 140 | { | |
| 141 | return threadSer ialNumber+ +; | |
| 142 | } | |
| 143 | ||
| 144 | publ ic Thread newThread( Runnable r ) | |
| 145 | { | |
| 146 | Thread thread = new Thread (r, groupN ame + "-" + getThrea dSerialNum ber()); | |
| 147 | thread .setDaemon (true); | |
| 148 | ||
| 149 | retu rn thread; | |
| 150 | } | |
| 151 | } | |
| 152 | ||
| 153 | /* * | |
| 154 | * | |
| 155 | * @author
|
|
| 156 | * | |
| 157 | * / | |
| 158 | cl ass Asynch Task | |
| 159 | im plements C allable<Ge nericAsync hResult> | |
| 160 | { | |
| 161 | Meth od method; | |
| 162 | Obje ct[] args; | |
| 163 | ||
| 164 | Asyn chTask(Met hod method , Object[] args) | |
| 165 | { | |
| 166 | this.m ethod = me thod; | |
| 167 | this.a rgs = args ; | |
| 168 | } | |
| 169 | ||
| 170 | publ ic Generic AsynchResu lt call() throws Exc eption | |
| 171 | { | |
| 172 | Object result = method.inv oke(target , args); | |
| 173 | ||
| 174 | return new Gener icAsynchRe sult(metho d, args, r esult); | |
| 175 | } | |
| 176 | } | |
| 177 | ||
| 178 | /* * | |
| 179 | * | |
| 180 | * @author
|
|
| 181 | * | |
| 182 | * / | |
| 183 | cl ass Listen erNotifica tionThread | |
| 184 | ex tends Thre ad | |
| 185 | { | |
| 186 | List enerNotifi cationThre ad(AsynchP roxyListen er listene r) | |
| 187 | { | |
| 188 | } | |
| 189 | ||
| 190 | @Ove rride | |
| 191 | pu blic void run() | |
| 192 | { | |
| 193 | while( true) | |
| 194 | { | |
| 195 | try | |
| 196 | { | |
| 197 | Future <GenericAs ynchResult > result = take(); | |
| 198 | listen er.result( result.get ()); | |
| 199 | } | |
| 200 | catch (I nterrupted Exception e) | |
| 201 | { | |
| 202 | break; | |
| 203 | } | |
| 204 | catch (E xecutionEx ception e) | |
| 205 | { | |
| 206 | e.prin tStackTrac e(); | |
| 207 | } | |
| 208 | } | |
| 209 | } | |
| 210 | } | |
| 211 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.