KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnet > Test


1 /*
2  * Test.java
3  *
4  * Created on 22. listopad 2003, 22:22
5  */

6
7 package SOFA.SOFAnet;
8
9 import java.io.*;
10 import java.util.*;
11 import SOFA.SOFAnode.TR.Impl.*;
12 import SOFA.SOFAnode.TR.*;
13 import SOFA.Util.VMProperties;
14 import java.rmi.*;
15
16 import SOFA.SOFAnet.Repository.*;
17
18 import SOFA.SOFAnet.TR.*;
19 import SOFA.SOFAnet.TR.Local.*;
20
21 import SOFA.SOFAnet.Core.*;
22 import SOFA.SOFAnet.Transport.*;
23 import SOFA.SOFAnet.Transport.RMI.*;
24
25 import java.rmi.Naming JavaDoc;
26 import java.net.MalformedURLException JavaDoc;
27
28 import SOFA.SOFAnet.NetNode;
29 import SOFA.SOFAnet.Local.RMI.*;
30
31 /**
32  *
33  * @author Ladislav Sobr
34  */

35 public class Test
36 {
37   
38   /** Creates a new instance of Test */
39   public Test()
40   {
41   }
42   
43   /**
44    * @param args the command line arguments
45    */

46   public static void main(String JavaDoc[] args)
47   {
48     try
49     {
50       if (args.length == 0 || args[0].length() == 0)
51       {
52         //klient
53
System.setProperty(VMProperties.NODE_NAME, "safir:1099");
54         System.setProperty("java.security.policy", "X:/SOFACVS/sofa/templates/conf/.java.policy");
55         System.setProperty("java.rmi.server.codebase", "file:///X:/SOFACVS/sofa/src");
56
57         System.setProperty("sofa.net.searchtimeout", "20000");
58         
59         NetNode instance = new NetNode(
60                                          new File("x:/tmp/TRdir"),
61                                          new File("x:/tmp/info"),
62                                          new File("x:/tmp/info/bin_bundles"),
63                                          new File("x:/tmp/info/share_client_cache")
64                                          );
65         instance.start();
66         
67         String JavaDoc bundleName = "my-bundle[1]";
68         /*
69         try
70         {
71           if (instance.localOps.isBundleInstalled(bundleName)) instance.localOps.uninstallBundle(bundleName, false, false);
72           instance.shareOps.stopShareClientOfBundle(bundleName, true, false);
73         }
74         catch (CoreException e)
75         {
76           e.printStackTrace();
77         }
78         */

79         /*
80         RMILocalInterface localServer = null;
81         try
82         {
83           localServer = (RMILocalInterface)Naming.lookup("rmi://safir:1099/SOFAnet/RMILocalServer");
84         }
85         catch (Exception e)
86         {
87           e.printStackTrace();
88         }
89         
90     
91         String componentFullName = "::CUNI::SOFA::demos::logdemo::Logger[0.0.1]";
92         try
93         {
94           localServer.obtainMissingComponent(componentFullName);
95         }
96         catch (RMILocalException e)
97         {
98           e.printStackTrace();
99         }
100         */

101       }
102       else
103       if (args[0].toLowerCase().compareTo("s") == 0)
104       {
105         //server
106
System.setProperty(VMProperties.NODE_NAME, "safir:2000");
107         System.setProperty("java.security.policy", "X:/SOFACVS/sofa/templates/conf/.java.policy");
108         System.setProperty("java.rmi.server.codebase", "file:///X:/SOFACVS/sofa/src");
109
110         NetNode instance = new NetNode(
111                                          new File("x:/tmp/TRdir_server"),
112                                          new File("x:/tmp/info_server"),
113                                          new File("x:/tmp/info_server/bin_bundles"),
114                                          new File("x:/tmp/info_server/share_client_cache")
115                                          );
116         Reporter.setShowDetailedExceptions(true);
117         
118         instance.start();
119         
120 // instance.shareOps.shareBundle("my-bundle[1]", 10, null, null, true, true);
121
/*
122         RMILocalInterface localServer = null;
123         try
124         {
125           localServer = (RMILocalInterface)Naming.lookup("rmi://safir:2000/SOFAnet/RMILocalServer");
126         }
127         catch (Exception e)
128         {
129           e.printStackTrace();
130         }
131         
132     
133         String componentFullName = "::CUNI::SOFA::demos::logdemo::Logger[0.0.1]";
134         try
135         {
136           localServer.obtainMissingComponent(componentFullName);
137         }
138         catch (RMILocalException e)
139         {
140           e.printStackTrace();
141         }
142 */

143       }
144       else
145       if (args[0].toLowerCase().compareTo("c") == 0)
146       {
147         //klient2
148
System.setProperty(VMProperties.NODE_NAME, "safir:2001");
149         System.setProperty("java.security.policy", "X:/SOFACVS/sofa/templates/conf/.java.policy");
150         System.setProperty("java.rmi.server.codebase", "file:///X:/SOFACVS/sofa/src");
151
152         System.setProperty("sofa.net.searchtimeout", "20000");
153         
154         NetNode instance = new NetNode(
155                                          new File("x:/tmp/TRdir2"),
156                                          new File("x:/tmp/info2"),
157                                          new File("x:/tmp/info2/bin_bundles"),
158                                          new File("x:/tmp/info2/share_client_cache")
159                                          );
160         instance.start();
161
162         String JavaDoc bundleName = "my-bundle[1]";
163         /*
164         try
165         {
166           if (instance.localOps.isBundleInstalled(bundleName)) instance.localOps.uninstallBundle(bundleName, false, false);
167           instance.shareOps.stopShareClientOfBundle(bundleName, true, false);
168         }
169         catch (CoreException e)
170         {
171           e.printStackTrace();
172         }
173         */

174 /*
175         RMILocalInterface localServer = null;
176         try
177         {
178           localServer = (RMILocalInterface)Naming.lookup("rmi://safir:2001/SOFAnet/RMILocalServer");
179         }
180         catch (Exception e)
181         {
182           e.printStackTrace();
183         }
184         
185     
186         String componentFullName = "::CUNI::SOFA::demos::logdemo::Logger[0.0.1]";
187         try
188         {
189           localServer.obtainMissingComponent(componentFullName);
190         }
191         catch (RMILocalException e)
192         {
193           e.printStackTrace();
194         }
195 */

196         
197       }
198       else
199       if (args[0].toLowerCase().compareTo("c2") == 0)
200       {
201         RMILocalInterface localServer = null;
202         try
203         {
204           localServer = (RMILocalInterface)Naming.lookup("rmi://safir:2000/SOFAnet/RMILocalServer");
205         }
206         catch (Exception JavaDoc e)
207         {
208           e.printStackTrace();
209         }
210         
211     
212         String JavaDoc componentFullName = "::CUNI::SOFA::demos::logdemo::Logger[0.0.1]";
213         try
214         {
215           if (false) localServer.obtainMissingComponent(componentFullName);
216           localServer.acquireComponent(componentFullName);
217           //localServer.releaseComponent(componentFullName);
218
//localServer.releaseComponent(componentFullName);
219
}
220         catch (RMILocalException e)
221         {
222           e.printStackTrace();
223         }
224         
225       }
226     }
227     catch (Exception JavaDoc e)
228     {
229       e.printStackTrace();
230     }
231           
232     /*
233     try
234     {
235     
236       if (args.length == 0 || args[0].toLowerCase().compareTo("s") != 0)
237       {
238         //klient
239         System.setProperty(VMProperties.NODE_NAME, "safir:1099");
240         System.setProperty("java.security.policy", "X:/SOFACVS/sofa/templates/conf/.java.policy");
241
242         Repository rep = new Repository(new File("x:/tmp/info"), new File("x:/tmp/bin_bundles"),
243                                         new File("x:/tmp/share_client_cache"));
244         TRInterface tr = null;
245         try
246         {
247           tr = new TRWrapper("x:/tmp/TRdir");
248         }
249         catch (Exception e)
250         {
251           e.printStackTrace();
252         }
253
254         RMITransportClient rmiTransportClient = new RMITransportClient();
255
256         LocalOps localOps = new LocalOps();
257         ShareOps shareOps = new ShareOps();
258         NetOps netOps = new NetOps();
259
260         localOps.setRepository(rep);
261         localOps.setTRInterface(tr);
262         localOps.setNetOps(netOps);
263
264         shareOps.setRepository(rep);
265
266         netOps.setRepository(rep);
267         netOps.setLocalOps(localOps);
268         netOps.setShareOps(shareOps);
269         netOps.setTransportInterface(rmiTransportClient);
270
271         rmiTransportClient.setNetOps(netOps);
272
273         String bundleName;
274         String nodeName = "safir:2000";
275         boolean result = false;
276         try
277         {
278           bundleName = "::CUNI::SOFA::demos::protodemo::Logger[0.0.1]";
279 // result = netOps.testPull(bundleName, nodeName);
280 // result = netOps.testPush(bundleName, nodeName, true);
281 // netOps.pushBundle(bundleName, nodeName, 1);
282           bundleName = "my-bundle[1]";
283 // netOps.synchroPullBundle(bundleName, nodeName);
284           netOps.pullBundle(bundleName, nodeName, "");
285         }
286         catch (CoreException e)
287         {
288           e.printStackTrace();
289         }
290
291       }
292       else
293       {
294         //server
295         System.setProperty(VMProperties.NODE_NAME, "safir:2000");
296         System.setProperty("java.security.policy", "X:/SOFACVS/sofa/templates/conf/.java.policy");
297         System.setProperty("java.rmi.server.codebase", "file:///X:/SOFACVS/sofa/src");
298
299
300         Repository rep = new Repository(new File("x:/tmp/info_server"), new File("x:/tmp/bin_bundles_server"),
301                                         new File("x:/tmp/share_client_cache_server"));
302         TRInterface tr = null;
303         try
304         {
305           tr = new TRWrapper("x:/tmp/TRdir_server");
306         }
307         catch (Exception e)
308         {
309           e.printStackTrace();
310         }
311
312         RMITransportClient rmiTransportClient = new RMITransportClient();
313
314         LocalOps localOps = new LocalOps();
315         ShareOps shareOps = new ShareOps();
316         NetOps netOps = new NetOps();
317
318         localOps.setRepository(rep);
319         localOps.setTRInterface(tr);
320         localOps.setNetOps(netOps);
321
322         shareOps.setRepository(rep);
323
324         netOps.setRepository(rep);
325         netOps.setLocalOps(localOps);
326         netOps.setShareOps(shareOps);
327         netOps.setTransportInterface(rmiTransportClient);
328
329         rmiTransportClient.setNetOps(netOps);
330
331         try
332         {
333           RMITransportServer rmiTransportServer = new RMITransportServer(netOps, shareOps);
334           Naming.rebind("//localhost:2000/SOFAnetRMITransportServer", rmiTransportServer);
335         }
336         catch (RemoteException e)
337         {
338           e.printStackTrace();
339         }
340         catch (MalformedURLException e)
341         {
342           e.printStackTrace();
343         }
344
345       }
346     }
347     catch (Exception e)
348     {
349       e.printStackTrace();
350     }
351     
352     */

353     /*
354      
355     Repository rep = new Repository(new File("x:/tmp/info"), new File("x:/tmp/bin_bundles"));
356     TRInterface tr = null;
357     try
358     {
359       tr = new TRWrapper("x:/tmp/TRdir");
360      
361 // ComponentInfo[] ca = new ComponentInfo[1];
362 // ca[0] = new ComponentInfoImpl("::CUNI::SOFA::demos::logdemo::logdemo", "0.0.1");
363 // tr.deleteComponents(ca, true, true);
364     }
365     catch (Exception e)
366     {
367       e.printStackTrace();
368     }
369      
370     LocalOps localOps = new LocalOps();
371     localOps.setRepository(rep);
372     localOps.setTRInterface(tr);
373      
374     ShareOps shareOps = new ShareOps();
375     shareOps.setRepository(rep);
376      
377     String bundleName;
378     try
379     {
380       bundleName = "::CUNI::SOFA::demos::protodemo::Logger[0.0.1]";
381       shareOps.shareBundle(bundleName, 3, null, true);
382       shareOps.shareBundle(bundleName, 4, null, true);
383       shareOps.shareBundle(bundleName, 3, null, true);
384       shareOps.shareBundle(bundleName, Licence.ALL_LICENCES, null, true);
385       shareOps.shareBundle(bundleName, 3, null, true);
386       shareOps.stopSharingBundle(bundleName, false);
387     }
388     catch(CoreException e)
389     {
390       e.printStackTrace();
391     }
392      
393      */

394     
395     /*
396     ComponentInfoImpl component, component2;
397     component = new ComponentInfoImpl("::CUNI::SOFA::demos::protodemo::Logger", "0.0.1");
398     try
399     {
400       bundleName = localOps.createSingleComponentBundle(component);
401       localOps.createBinaryBundle(bundleName, true);
402       localOps.uninstallBundle(bundleName, true, false);
403       localOps.installBundle(bundleName, false);
404     }
405     catch(localOps.BundleOpException e)
406     {
407       e.printStackTrace();
408     }
409      
410     component = new ComponentInfoImpl("::CUNI::SOFA::demos::logdemo::logdemo", "0.0.1");
411     try
412     {
413       bundleName = localOps.createCompleteComponentBundle(component);
414       localOps.createBinaryBundle(bundleName, true);
415       localOps.uninstallBundle(bundleName, true, false);
416       localOps.installBundle(bundleName, false);
417     }
418     catch(localOps.BundleOpException e)
419     {
420       e.printStackTrace();
421     }
422      
423     component = new ComponentInfoImpl("::CUNI::SOFA::demos::logdemo::logdemo", "0.0.1");
424     component2 = new ComponentInfoImpl("::CUNI::SOFA::demos::logdemo::Logger", "0.0.2");
425     ComponentInfo[] comps = new ComponentInfo[2];
426     comps[0] = component;
427     comps[1] = component2;
428      
429     try
430     {
431       bundleName = "my-bundle[1]";
432       localOps.createUserBundle(bundleName, comps, true);
433       localOps.createBinaryBundle(bundleName, true);
434       localOps.uninstallBundle(bundleName, true, false);
435       localOps.installBundle(bundleName, false);
436     }
437     catch(localOps.BundleOpException e)
438     {
439       e.printStackTrace();
440     }
441      */

442     
443 /*
444     OutputTriggers outputTriggers = rep.getOutputTriggers();
445  
446     List l;
447     BundleNameFilter bundleFilter = new BundleNameFilter();
448     l = bundleFilter.getPatterns();
449     l.add("::CUNI::SOFA::xxx[0.1.0]");
450     l.add("nas-balicek-0.0.1");
451     l.add("*[>0.0.0]*");
452     NodeNameFilter nodeFilter = new NodeNameFilter();
453     l = nodeFilter.getPatterns();
454     l.add("sofa://safir:2000");
455     l.add("195.113.27.80/10");
456  
457  
458  
459     Calendar cal = Calendar.getNetNode();
460     cal.roll(Calendar.DAY_OF_MONTH, 5);
461     Date validTo = cal.getTime();
462     outputTriggers.addOutputTrigger("my_oe", false, "popisek", true, bundleFilter, nodeFilter, null, validTo, "ccccc", "rrrrrr");
463     outputTriggers.addOutputTrigger("my_oe", true, "popisek", true, bundleFilter, nodeFilter, null, validTo, "ccccc", "rrrrrr");
464     outputTriggers.addOutputTrigger("", true, "popisek", true, bundleFilter, nodeFilter, null, validTo, null, null);
465     outputTriggers.addOutputTrigger("", true, "popisek", true, bundleFilter, nodeFilter, null, validTo, "ccccc", "rrrrrr");
466  
467     InputTriggers inputTriggers = rep.getInputTriggers();
468  
469     OutputTrigger outputTrigger = new OutputTrigger("", null);
470     outputTrigger.setBundleFilter(bundleFilter);
471     outputTrigger.setValidFrom(validTo);
472     outputTrigger.setDescription("jjjjjjjjjeeeee");
473     NodeNameLicList nodeLicList = new NodeNameLicList();
474     nodeLicList.add("sofa://safir", -1);
475     nodeLicList.add("safir", -2);
476     nodeLicList.add("192.168.1.0", 4);
477     NodeNameList nodeNameList = new NodeNameList();
478     nodeNameList.add("sofa://safir:2000");
479     nodeNameList.add("195.113.27.80");
480  
481  
482     inputTriggers.addInputTrigger("my_ie", false, InputTrigger.TYPE_ALL, "hulahula", true, bundleFilter, nodeFilter, null, validTo, "sdsd", "ruleeeeeee", InputTrigger.ACTION_INSTALL | InputTrigger.ACTION_DELETE, -1, null, null, null);
483     inputTriggers.addInputTrigger("my_ie", true, InputTrigger.TYPE_ALL, "hulahula", true, bundleFilter, nodeFilter, null, validTo, "sdsd", "ruleeeeeee", InputTrigger.ACTION_INSTALL | InputTrigger.ACTION_DELETE, -1, null, null, null);
484     inputTriggers.addInputTrigger("", true, InputTrigger.TYPE_ALL, "hulahula", true, bundleFilter, nodeFilter, null, validTo, "sdsd", "ruleeeeeee", InputTrigger.ACTION_SHARE | InputTrigger.ACTION_ALLOW_PULL, -2, outputTrigger, null, null);
485     inputTriggers.addInputTrigger("", true, InputTrigger.TYPE_ALL, "hulahula", true, bundleFilter, nodeFilter, null, validTo, "sdsd", "ruleeeeeee", InputTrigger.ACTION_SHARE | InputTrigger.ACTION_PUSH | InputTrigger.ACTION_PUSH_OFFER, 3, null, nodeLicList, nodeNameList);
486  
487  
488  
489     NodeInfo ni = new NodeInfo();
490     boolean b2;
491     try
492     {
493       ni.setNodeName("sofa://safir:2000");
494       b2 = ni.matchPattern("safir.kolej.mff.cuni.cz");
495       b2 = ni.matchPattern("sofa://cuni.cz");
496       ni.setNodeName("sofa://www.lupa.cz:2000");
497       b2 = ni.matchPattern("195.113.27.80/10");
498       b2 = ni.matchPattern("safir.kolej.mff.cuni.cz");
499       b2 = ni.matchPattern("sofa://cz");
500     }
501     catch (Exception e)
502     {
503       System.out.println(e.getMessage());
504     }
505  
506     InstalledBundles installedBundleContents = rep.getInstalledBundles();
507  
508     ComponentInfoImpl [] cs = new ComponentInfoImpl[3];
509  
510     cs[0] = ComponentInfoImpl.fromString("::CUNI::SOFA::xxx[0.1.0]");
511     cs[1] = ComponentInfoImpl.fromString("::CUNI::SOFA::yyy[0.0.1]");
512     cs[2] = ComponentInfoImpl.fromString("::CUNI::bubu::haf::z[2.0.0]");
513     InstalledBundle installedBundleContent = installedBundleContents.addInstalledBundle("::CUNI::SOFA::xxx[0.1.0]", cs);
514  */

515     
516 /*
517     BundleInfo bundleInfo = new BundleInfo();
518     try
519     {
520       bundleInfo.fromFilename("-CUNI-SOFA-demos-cplayer-Main-0.0.1");
521       bundleInfo.fromFilename("-CUNI-SOFA-demos-cplayer-Main-0.0.1-#");
522       bundleInfo.fromFilename("nas-balicek-0.0.1");
523       bundleInfo.fromBundleName("::CUNI::SOFA::demos::cplayer::Main[0.0.1]");
524       bundleInfo.fromBundleName("::CUNI::SOFA::demos::cplayer::Main[0.0.1]#");
525       bundleInfo.fromBundleName("nas-balicek[0.0.1]");
526     }
527     catch (Exception e)
528     {
529     }
530  
531     try
532     {
533       bundleInfo.fromFilename("-CUNI-SOFA-demos-cplayer-Main-0.0.1");
534       boolean x;
535       x = bundleInfo.matchPattern("*[*]*");
536       x = bundleInfo.matchPattern("::CUNI::*[*]*");
537       x = bundleInfo.matchPattern("::CUNI::SO*[*]*");
538       x = bundleInfo.matchPattern("::?::SOFA[*]*");
539       x = bundleInfo.matchPattern("balicek[*]*");
540       x = bundleInfo.matchPattern("*[0.0.1]*");
541       x = bundleInfo.matchPattern("*[03]*");
542       x = bundleInfo.matchPattern("*[>0.0.0]*");
543       x = bundleInfo.matchPattern("*[<=1.1.1]*");
544       x = bundleInfo.matchPattern("*[*]*");
545       x = bundleInfo.matchPattern("*[*]#");
546       x = bundleInfo.matchPattern("*[*]");
547     }
548     catch (Exception e)
549     {
550     }
551  */

552   }
553   
554 }
555
Popular Tags