Last commit for WorkletTest4.java: e648691acebb1ed23bc2912ad66eee036b3bed6a

alex's newer changes. bytecode serialisation now happens within the

gskc [2002-12-17 22:14:42]
alex's newer changes. bytecode serialisation now happens within the
Worklet code, ie transparent to whoever codes the WJ
  1. /**
  2.  *@author: Peter Davis
  3.  *ptd7@cs.columbia.edu
  4.  *
  5.  *Modification of psl.worklets.SystemDispatch.java
  6.  *
  7.  *This class was made from SystemDispatch.java (author: Gaurav Kc, gskc@cs.columbia.edu)
  8.  *except that modifications have been made to handle multiple junctions.
  9.  
  10.  *This program deploys worklets to multiple junctions,
  11.  *as a demonstration of multiple junction capability
  12.  *
  13.  *
  14.  *Testing:
  15.  *Worklet containing java program called Test.java (Test.java simply prints something to stdout)
  16.  *sent from diamond.cs.columbia.edu
  17.   to:
  18.   disco.cs.columbia.edu
  19.   dynamo.cs.columbia.edu
  20.   dynasty.cs.columbia.edu
  21.   *status:
  22.   *8/7/2001:
  23.   *2:30 p.m.
  24.  
  25.  
  26.   *works for config file of:
  27. Test,dynamo.cs.columbia.edu,WVM1,9101
  28. Test,disco.cs.columbia.edu,WVM1,9101
  29. Test,dynasty.cs.columbia.edu,WVM1,910
  30.  
  31.   setup:
  32.   WorkletTest run on diamond.cs
  33.   psl.worklets.WVM run on {disco.cs,dynamo.cs,dynasty.cs}.columbia.edu
  34.   Application successfully sent to all three hosts through sockets.
  35.   RMI did not work for all three hosts.
  36.  
  37.   *
  38.   *
  39.   */
  40.  
  41. package psl.worklets;
  42.  
  43. import java.io.*;
  44. import java.net.*;
  45. import psl.worklets.*;
  46. import java.util.*;
  47.  
  48. public class WorkletTest4 implements Serializable {
  49.  
  50. private static final int DEFAULT_PORT = 9100;
  51.  
  52. public static void main(String args[]) {
  53. WorkletTest4 wt = new WorkletTest4();
  54. }
  55.  
  56. private WorkletTest4() {
  57.  
  58. System.out.println("WORKLET TEST 4 , ALL WORKLET JUNCTIONS ARE KEPT AS BYTE ARRAYS UNTIL TARGET");
  59. /*****modification, ptd7***/
  60. try{
  61. WVM wvm = new WVM(new Object(), InetAddress.getLocalHost().getHostAddress(),
  62. "WorkletTest_4");
  63. Worklet wkl = new Worklet(null);
  64.  
  65. String App = null;
  66. String rHost = null;
  67. String rName = null;
  68. int rPort = 0;
  69.  
  70. FileHandle fh = new FileHandle("config.txt",FileHandle.IN);
  71. String input_info =null;
  72.  
  73. while((input_info = fh.readln()) != null){
  74. StringTokenizer reader = new StringTokenizer(input_info,",");
  75. if(reader.countTokens() >=4){
  76.  
  77. //System.out.println("input from cfg file is: " + input_info);
  78. if(input_info.charAt(0) != '#' && input_info.charAt(0) != ' '){
  79. /**make sure that it is valid input**/
  80. /**input must be of form: <app>,<host>,<name>,<port>**/
  81. App = reader.nextToken();
  82. rHost = reader.nextToken();
  83. rName = reader.nextToken();
  84. try{
  85. rPort = Integer.parseInt(reader.nextToken());
  86. System.out.println("error parsing port. . . setting to "
  87. + DEFAULT_PORT +" . . .");
  88. rPort = DEFAULT_PORT;
  89. }
  90. /*************add new junctions********************/
  91. /****testing***/
  92.  
  93. /****end testing***/
  94. final Class appClass = Class.forName(App);
  95. // // final Class appClass = Class.forName("gskc.TicTacToe");
  96.  
  97.  
  98. String u = new String("http://"+java.net.InetAddress.getLocalHost().getHostAddress()+":"+wvm.transporter._webPort+"/");
  99. URL x = new URL(u);
  100. // try{
  101. // ByteArrayOutputStream baoStream = new ByteArrayOutputStream();
  102. // ObjectOutputStream ooStream = new ObjectOutputStream(baoStream);
  103.  
  104. //create byte array out of actual junction to use first
  105. wkl.addJunction(new WorkletJunction(rHost, rName, rPort) {
  106. public void init(Object system, WVM wvm) {
  107. System.out.println("ORIGINAL JUNCTION"); }
  108. public void execute() {
  109. WVM.out.println("\t --- Totally New Component ---");
  110. try {
  111. // System.out.println("Calling the loader here somewhere");
  112. // System.out.println("Declaring class: " + appClass.getDeclaringClass().getNa
  113.  
  114. // final Class appClass = Class.forName(appName);
  115.  
  116. System.out.println(appClass.getClassLoader().getClass().getName());
  117. appClass.newInstance();
  118. } catch (InstantiationException e) {
  119. WVM.out.println("Exception: " + e.getMessage());
  120. e.printStackTrace();
  121. } catch (IllegalAccessException e) {
  122. WVM.out.println("Exception: " + e.getMessage());
  123. e.printStackTrace();
  124. } catch (Exception e) {
  125. e.printStackTrace();
  126. }
  127. }
  128. },x);
  129.  
  130. // byte []wjbytes = baoStream.toByteArray();
  131. // baoStream.close();
  132.  
  133. // String u = new String("http://"+java.net.InetAddress.getLocalHost().getHostAddress()+":"+wvm.transporter._webPort+"/");
  134. // // System.out.println("\n\nSENDING URL: " + u);
  135. // URL x = new URL(u);
  136.  
  137. // //add byte array along with dummy empty junction tht has only destination info
  138. // wkl.addJunction(new WorkletJunction(rHost, rName, rPort,App,wkl.wid) {
  139. // public void init(Object system, WVM wvm) {}
  140. // public void execute() {}
  141. // },wjbytes,x);
  142.  
  143. // } catch (IOException ioe){
  144. // ioe.printStackTrace();
  145. // System.exit(-1);
  146. // }
  147.  
  148. /* } else {
  149. wkl.addJunction(new WorkletJunction(rHost, rName, rPort,App,wkl.wid) {
  150. public void init(Object system, WVM wvm) { }
  151. public void execute() {
  152. WVM.out.println("\t --- Totally New Component ---");
  153. try {
  154. // System.out.println("Calling the loader here somewhere");
  155. // System.out.println("Declaring class: " + appClass.getDeclaringClass().getNa
  156.  
  157. // final Class appClass = Class.forName(appName);
  158.  
  159. System.out.println(appClass.getClassLoader().getClass().getName());
  160. appClass.newInstance();
  161. } catch (InstantiationException e) {
  162. WVM.out.println("Exception: " + e.getMessage());
  163. e.printStackTrace();
  164. } catch (IllegalAccessException e) {
  165. WVM.out.println("Exception: " + e.getMessage());
  166. e.printStackTrace();
  167. } catch (Exception e) {
  168. e.printStackTrace();
  169. }
  170. }
  171. });
  172. }*/
  173.  
  174.  
  175.  
  176. System.out.println("just added a junction at: ");
  177. System.out.println("App: " + App+ " rHost: " + rHost
  178. + " rName: " + rName + " rPort: " + rPort );
  179.  
  180. /***********end, add new junctions*****************/
  181. }
  182. }
  183. }
  184. fh.close();
  185.  
  186.  
  187. /*****end modification, ptd7***/
  188. System.out.println("about to deploy worklet");
  189. wkl.deployWorklet(wvm); //deploy worklet, with junctions from config file
  190. System.out.println("just deployed worklet");
  191.  
  192. } catch (UnknownHostException e) {
  193. WVM.out.println("Exception: " + e.getMessage());
  194. e.printStackTrace();
  195. System.exit(0);
  196. } catch (ClassNotFoundException e) {
  197. WVM.out.println("Exception: " + e.getMessage());
  198. e.printStackTrace();
  199. System.exit(0);
  200. } catch (Exception e) {
  201. WVM.out.println("Exception: " + e.getMessage());
  202. e.printStackTrace();
  203. System.exit(0);
  204. }
  205. }
  206. }
  207.  
  208.  
  209.