]> rtime.felk.cvut.cz Git - orte.git/blob - orte/java/src/org/ocera/orte/examples/hello/Publisher.java
JORTE: don't use finalizers in Java classes
[orte.git] / orte / java / src / org / ocera / orte / examples / hello / Publisher.java
1 /* Publisher.java */
2
3 /**
4  * Class Publisher provides methods for creating and working
5  * with the ORTE publisher.
6  *
7  * @author Lukas Pokorny (lukas_pokorny@centrum.cz)
8  * @author CTU FEE Prague - Department of Control Engineering (dce.felk.cvut.cz)
9  * @author Project ORTE - OCERA Real Time Ethernet (www.ocera.org)
10  * @author dedication to Kj
11  * @version 0.1
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  */
24
25 import org.ocera.orte.*;
26 import org.ocera.orte.types.*;
27
28
29 public class Publisher {
30
31    // load native library 'libjorte.so'
32    static 
33    {
34          System.loadLibrary("jorte");      
35    }
36
37   public static void main(String[] args)
38   {
39
40     System.out.println(":j: * ********************************************* *"); 
41     System.out.println(":j: *         JORTE Publisher is starting..         *");
42     System.out.println(":j: * ********************************************* *");
43         
44         // set publisher's parameters
45     NtpTime persistence = new NtpTime(3);
46     int strength = 1;
47     // 
48     MyEvents events = new MyEvents();
49     
50     /**
51      *  Create a new Application Domain for a Publisher.
52      * (Constructor without arguments creates the default Application Domain.)
53      */ 
54      // creates default app domain
55      //DomainApp appDomain = new DomainApp();
56      // creates user defined app domain
57           
58     DomainApp appDomain = new DomainApp(ORTEConstant.ORTE_DEFAULT_DOMAIN,
59                                         DomainProp.defaultPropsCreate(),
60                                         events,
61                                         false); 
62     if (appDomain == null)
63         {
64       System.out.println(":!j: cannot create default domain!");
65       return;
66         }
67     
68     // create a HelloMessage instance 
69         HelloMsg hellomsg = new HelloMsg(appDomain,"Example HelloMsg");
70     
71     // set basic subscription properties
72     PublProp publProp = new PublProp(hellomsg.getTopic(),
73                                          hellomsg.getType(),                                    
74                                      persistence,
75                                                                          strength);
76     
77     System.out.println(":j: set publication properties..");             
78
79     /* set verbosity mode - just uncomment the line bellow */
80     // JOrte.verbositySetOptions("ALL:10");
81
82         // create a publication    
83     Publication pub = appDomain.createPublication(publProp,
84                                                       hellomsg);                
85     if (pub == null)
86     {
87       System.out.println(":j!: publisher not created!");
88       return;
89     }
90     System.out.println(":j: publisher created!");
91     System.out.println(":j: * ********************************************* *");        
92     System.out.println(":j: start sending data:");
93     System.out.println(":j: * ********************************************* *");
94     
95     for(int i = 0; i < 40; i++)
96         {
97           pub.send(hellomsg); 
98           System.out.println("<<  data to send: " + hellomsg);
99           JOrte.sleepMs(1000);
100           System.out.println(" ");
101         }
102     pub.destroy();
103   } 
104
105 }