1 package org.bsf.remoting; 2 3 import java.io.InputStream ; 4 import java.io.IOException ; 5 6 import org.bsf.remoting.BSFImage; 7 import org.bsf.remoting.RemoteService; 8 9 public class RemoteServiceMock implements RemoteService{ 10 11 private int statefullIndex = 0; 12 13 public int compute(int varA, int varB, int operator) { 14 int result = 0; 15 switch (operator) { 16 case OPERATOR_ADD : 17 result = varA + varB; 18 break; 19 case OPERATOR_MINUS: 20 result = varA - varB; 21 break; 22 case OPERATOR_MULT: 23 result = varA * varB; 24 break; 25 } 26 try { 27 Thread.sleep(100); 28 } catch (InterruptedException e) {} 29 return result; 30 } 31 32 public void throwsException() throws Exception { 33 try { 34 Thread.sleep(100); 35 } catch (InterruptedException e) {} 36 throw new Exception ("New Exception message"); 37 } 38 39 public String upperWord(String word) { 40 if (word == null) 41 return null; 42 sleep100(); 43 return word.toUpperCase(); 44 } 45 46 private void sleep100() { 47 try { 48 Thread.sleep(100); 49 } catch (InterruptedException e) {} 50 } 51 52 53 57 public BSFImage getBSFImage(){ 58 byte[] buffer = new byte[1024*100]; 60 byte[] data = null; 61 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 62 InputStream is = loader.getResourceAsStream("images/TeamImage.jpg"); 63 int i = 0; 64 while(true){ 65 int nextByte = 0; 66 try { 67 nextByte = is.read(); 68 } catch (IOException e) { 69 throw new RuntimeException (e.getLocalizedMessage()); 70 } 71 if (nextByte == -1){ 72 data = new byte[i]; 73 System.arraycopy(buffer, 0, data, 0, i); 74 break; 75 } 76 buffer[i] = (byte)nextByte; 77 i++; 78 } 79 sleep100(); 80 return new BSFImage("BSF Architecture Team", data); 81 } 82 83 84 public String createStatefull() { 85 statefullIndex++; 86 sleep100(); 87 return "EJB" + statefullIndex; 88 } 89 90 public String remoteStatefulCall(){ 91 sleep100(); 92 return "CallOnEJB" + statefullIndex; 93 } 94 } 95 | Popular Tags |