]> rtime.felk.cvut.cz Git - orte.git/blob - orte/java/src/org/ocera/orte/Publication.java
JORTE: don't force application domain destruction
[orte.git] / orte / java / src / org / ocera / orte / Publication.java
1 /* Publication.java */
2
3 /**
4  * Class Publication 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 package org.ocera.orte;
26 import java.nio.ByteBuffer;
27
28 import org.ocera.orte.types.*;
29
30
31 public class Publication {
32
33   private long handle;
34   private org.ocera.orte.types.MessageData msgData;
35
36   private boolean b;
37 /*
38   private int callbackEnvHandle = 0;
39 */
40   /**
41    * getHandle - returns handler of the publication
42    *
43    * @return handler of the publication
44    */
45    public long getHandle()
46    {
47      return this.handle;
48    }
49
50
51   /**
52    * constructor
53    *
54    */
55
56   /* TODO   
57    * nemelo by se v jORTEPublicationCreate misto cele instance predavat 
58    * jen instance.data ????? resp instance.getData???? 
59    * 
60    * 
61    */
62    public Publication(Domain d,
63                       PublProp publProp,
64                                           MessageData instance)
65   {
66         this.handle = jORTEPublicationCreate(d.handle,
67                                              publProp.getTopic(),
68                                              publProp.getTypeName(),
69                                                                                  instance.getBuffer(),
70                                          publProp.getPersistence(),
71                                                                              publProp.getStrength());
72                                       // int sendCallBack,
73                                           // sendCallBackParam,
74                                       // NtpTime cbDelay
75   }
76
77
78  /**
79   * destroy - Removes a publication.
80   * @return False if bad publication handle, True if  succesful.
81   */
82   public
83   boolean destroy()
84   {
85         /* TODO vyradit vypis na nasledujici radce */
86         System.out.println(":j: publication destroy called..");
87         // destroy publication
88         if(!jORTEPublicationDestroy(this.handle)) 
89         {
90             System.out.println(":j!: publication destroy fault!");
91             return false;               
92         }
93     System.out.println(":j: publication destroy successfull..");
94     return true;
95   }
96
97
98  /**
99   * send - Send the publication.
100   * @return void
101   */
102   public void send(MessageData instance)
103   {
104     //this.msgData.write(); // volat v Publisher.java
105     instance.write(); 
106
107     b = jORTEPublicationSend(this.handle);
108     if(!b) System.out.println(":j!: Sending Publication Fault!");
109     return;
110   }
111
112   
113   /**
114    * Get Publication properties.
115    * @return Publication properties.
116    */
117   public PublProp getProperties()
118   {
119         PublProp sp = new PublProp();
120     sp = jORTEPublicationPropertiesGet(this.handle);    
121         return sp;
122   }
123   
124   /**
125    * Set Publication properties.
126    * @return True - setting new properties Ok, False - setting new properties fault.  
127    */
128   public boolean setProperties(PublProp sp)
129   {
130         boolean  b;
131
132         // modify PublProp object - sp    
133         b = jORTEPublicationPropertiesSet(this.handle, sp);     
134         if(b == false) 
135         {
136         System.out.println(":j!: set PublProp failed! (bad Subs. handle)"); 
137                 return false; 
138         } 
139         return true;
140   }
141   
142   
143   /**
144    * Get Publication status.
145    * @return Status of Publication.  
146    */
147   public Status getStatus()
148   {
149     Status ps = new Status();
150         ps = jORTEPublicationGetStatus(this.handle);
151         return ps;
152   }
153
154   
155   /**
156    * Waits for given number of subscriptions. 
157    * @param Time how long to wait.
158    * @param Number of retries if specified number of subscriptions not reached.
159    * @param Desired number of subscriptions.
160    * @return ORTE_OK if succesful, ORTE_BAD_HANDLE if bad publication handle, 
161    *         ORTE_TIMEOUT if number of retries has been exhausted.   
162    */
163   public int waitForSubscriptions(NtpTime wait,
164                                           long retries,
165                                                           long noSubscription)   
166   { 
167     int i;
168         i = jORTEPublicationWaitForSubscriptions(this.handle,
169                                                          wait,
170                                                          retries,
171                                                                                          noSubscription);
172     return i; 
173   }
174   
175   
176  /* ****************************************************************** *
177   *                                                                    *
178   *                         native methods                             *
179   *                                                                    *
180   * ****************************************************************** */
181
182   private native
183   long jORTEPublicationCreate(long appDomainHandle,
184                              String topic,
185                              String typeName,
186                                                          ByteBuffer buffer,
187                                                          NtpTime persistence,
188                              int strength);
189                           // int sendCallBack, -->NULL
190                           // sendCallBackParam,--> NULL
191                           // NtpTime sendCallBackDelay
192
193   private native
194   boolean jORTEPublicationDestroy(long publHandle);
195
196   private native
197   boolean jORTEPublicationSend(long publHandle);
198                                        
199
200   private native
201   PublProp jORTEPublicationPropertiesGet(long publHandle);
202   
203   private native
204   boolean jORTEPublicationPropertiesSet(long publHandle,
205                                                 PublProp publProps);
206
207   private native
208   Status jORTEPublicationGetStatus(long publHandle);
209
210   private native
211   int jORTEPublicationWaitForSubscriptions(long publHandle,
212                                                NtpTime wait,
213                                                                            long retries,
214                                                                                    long noSubscription);
215
216 }