1 22 23 package org.jboss.aspects.asynchronous.aspects; 24 25 import org.jboss.aspects.asynchronous.AsynchronousConstants; 26 import org.jboss.aspects.asynchronous.AsynchronousResponse; 27 import org.jboss.aspects.asynchronous.AsynchronousTask; 28 import org.jboss.aspects.asynchronous.ThreadManagerResponse; 29 30 34 35 public class AsynchronousFacadeImpl 36 37 implements AsynchronousFacade, AsynchronousConstants 38 { 39 40 private AsynchronousFacadeFields asynchronousFacadeFields = null; 41 42 public AsynchronousFacadeImpl() 43 { 44 45 asynchronousFacadeFields = 46 47 new AsynchronousFacadeFieldsThreadLocalImpl(); 48 49 } 50 51 private AsynchronousFacadeFields getAsynchronousFacadeFields() 52 { 53 54 return asynchronousFacadeFields; 55 56 } 57 58 public AsynchronousTask getAsynchronousTask() 59 { 60 61 return getAsynchronousFacadeFields().getAsynchronousTask(); 62 63 } 64 65 public void setTimeout(long timeout) 66 { 67 68 getAsynchronousFacadeFields().setTimeout(timeout); 69 70 } 71 72 public long getTimeout() 73 { 74 75 return getAsynchronousFacadeFields().getTimeout(); 76 77 } 78 79 public void setAsynchronousTask(AsynchronousTask asynchronousTask) 80 { 81 82 getAsynchronousFacadeFields().setAsynchronousTask(asynchronousTask); 83 84 } 85 86 public void setId(String id) 87 { 88 89 getAsynchronousFacadeFields().setId(id); 90 91 } 92 93 public String getId() 94 { 95 96 return getAsynchronousFacadeFields().getId(); 97 98 } 99 100 public ThreadManagerResponse getThreadManagerResponse() 101 { 102 103 return getAsynchronousTask().getResponse(); 104 105 } 106 107 public AsynchronousResponse waitForResponse() 108 { 109 110 return waitForResponse(getAsynchronousTask()); 111 112 } 113 114 public Object getReturnValue() 115 { 116 117 return getReturnValue(getAsynchronousTask()); 118 119 } 120 121 public boolean isDone() 122 { 123 124 return isDone(getAsynchronousTask()); 125 126 } 127 128 public int getResponseCode() 129 { 130 131 return getResponseCode(getAsynchronousTask()); 132 133 } 134 135 public AsynchronousResponse waitForResponse(AsynchronousTask asynchronousTask) 136 { 137 138 if (asynchronousTask.getResponse().getResponseCode() 139 140 == AsynchronousConstants.OK) 141 { 142 143 AsynchronousResponse atask = 144 145 (AsynchronousResponse) asynchronousTask 146 147 .getResponse() 148 149 .getResult(); 150 151 return atask; 152 153 } 154 155 return asynchronousTask.getResponse(); 156 157 } 158 159 public Object getReturnValue(AsynchronousTask asynchronousTask) 160 { 161 162 if (asynchronousTask == null) 163 164 return null; 165 166 AsynchronousResponse asynchronousResponse = 167 168 waitForResponse(asynchronousTask); 169 170 if (asynchronousResponse.getResponseCode() == OK) 171 172 return asynchronousResponse.getResult(); 173 174 else 175 176 return null; 177 178 } 179 180 public boolean isDone(AsynchronousTask synchronousTask) 181 { 182 183 if (synchronousTask == null) 184 185 return false; 186 187 else 188 189 return synchronousTask.isDone(); 190 191 } 192 193 public int getResponseCode(AsynchronousTask synchronousTask) 194 { 195 196 return (waitForResponse(synchronousTask).getResponseCode()); 197 198 } 199 200 } 201 202 | Popular Tags |