]> rtime.felk.cvut.cz Git - orte.git/blob - orte/java/src/org/ocera/orte/Subscription.java
JORTE: don't force application domain destruction
[orte.git] / orte / java / src / org / ocera / orte / Subscription.java
1 /* Subscription.java */
2
3 /**
4  * Class Subscription provides methods for creating and working
5  * with the ORTE subscribtion.
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 Subscription {
32
33    private long handle;
34    private long callbackContextHandle = 0;
35
36   /**
37    * Get Subscription's handle.
38    * @return Handle of the subscription.
39    */
40    public long getHandle()
41    {
42      return this.handle;
43    }
44
45
46   /**
47    * constructor 
48    */
49   /* PROC protected??? - aby sel volat jen z tridy Domain */
50   protected Subscription(Domain appDomain,
51                          SubsProp subsProp,                         
52                                                  MessageData message,
53                                                  SubscriptionCallback subsCallback)
54   {
55         this.handle = jORTESubscriptionCreate(appDomain.handle,
56                                               subsProp.getMode(),
57                                               subsProp.getType(),
58                                               subsProp.getTopic(),
59                                               subsProp.getTypeName(),
60                                               message.getBuffer(),
61                                               message,
62                                                                                   subsProp.getDeadline(),
63                                                               subsProp.getMinSeparation(),
64                                                               subsCallback,
65                                        // callBackParam 
66                                                               subsProp.getMulticastIPAddr());
67   }
68
69  /**
70   * Removes a Subscription.
71   * @return False if bad Publication handle, True if  succesful
72   */
73   public
74   boolean destroy()
75   {
76         /* TODO vyradit vypis na nasledujici radce */
77         System.out.println(":j: subscription destroy called..");
78         // destroy subscription
79         if(!jORTESubscriptionDestroy(this.handle)) 
80         {
81             System.out.println(":j!: subscription destroy fault!");
82             return false;               
83         }
84     System.out.println(":j: subscription destroy successfull..");
85     return true;
86     
87   }
88  
89   /**
90    * Get Subscription properties.
91    * @return Subscription properties.
92    */
93   public SubsProp getProperties()
94   {
95         SubsProp sp = new SubsProp();
96     sp = jORTESubscriptionPropertiesGet(this.handle);   
97         return sp;
98   }
99   
100   /**
101    * Set Subscription properties.
102    * @return True - setting new properties Ok, False - setting new properties fault.  
103    */
104   public boolean setProperties(SubsProp sp)
105   {
106         boolean  b;
107
108         // modify SubsProp object - sp    
109         b = jORTESubscriptionPropertiesSet(this.handle, sp);    
110         if(b == false) 
111         {
112         System.out.println(":j!: set SubsProp failed! (bad Subs. handle)"); 
113                 return false; 
114         } 
115         return true;
116   }
117   
118   
119   /**
120    * Get Subscription status.
121    * @return Status of Subscription.  
122    */
123   public Status getStatus()
124   {
125     Status ss = new Status();
126         ss = jORTESubscriptionGetStatus(this.handle);
127         return ss;
128   }
129
130  
131   /**
132    * Waits for given number of publications.
133    * @param Time how long to wait.
134    * @param Number of retries if specified number of publications not reached.
135    * @param Desired number of publications.
136    * @return ORTE_OK if succesful, ORTE_BAD_HANDLE if bad subscription handle, 
137    *         ORTE_TIMEOUT if number of retries has been exhausted.   
138    */
139   public int waitForPublications(NtpTime wait,
140                                          long retries,
141                                                          long noPublication)   
142   { 
143     int i;
144         i = jORTESubscriptionWaitForPublications(this.handle,
145                                                          wait,
146                                                          retries,
147                                                                                          noPublication);
148     return i; 
149   }
150   
151   /* TODO - dodelat middle C zdrojak !! */
152   /**
153    * Read data
154    * @param Time how long to wait.
155    * @param Number of retries if specified number of publications not reached.
156    * @param Desired number of publications.
157    * @return ORTE_OK if succesful, ORTE_BAD_HANDLE if bad subscription handle, 
158    *         ORTE_TIMEOUT if number of retries has been exhausted.   
159    */
160   public boolean pull(long subsHandle)
161   { 
162     int b = jORTESubscriptionPull(subsHandle);
163     if (b == ORTEConstant.ORTE_BAD_HANDLE) 
164     {
165       System.out.println(":j!: method pull failed  [bad subsHandle]!");
166       return false;
167     }   
168     return true; 
169   }
170   
171   /* TODO - dodelat!! */
172   public void patternCreate()
173   {}
174   /* TODO - dodelat!! */
175   public void patternRemove()
176   {}
177   /* TODO - dodelat!! */
178   public void patternDelete()
179   {}
180   
181   
182   
183 /* ****************************************************************** *
184  *                                                                    *
185  *                         native methods                             *
186  *                                                                    *
187  * ****************************************************************** */
188
189   private native
190   long jORTESubscriptionCreate(long appDomainHandle,
191                                int subsmode,  /*! union */
192                                int substype,  /*! union */
193                                String topic,
194                                String typeName,
195                                ByteBuffer buffer,
196                                MessageData message,
197                                                           NtpTime deadline,
198                                NtpTime minSeparation,
199                                SubscriptionCallback cb,
200                              // recvCallBackParam
201                                long multicastIPAddress);
202
203   private native
204   boolean jORTESubscriptionDestroy(long subsHandle);
205
206   private native
207   SubsProp jORTESubscriptionPropertiesGet(long subsHandle);
208   
209   private native
210   boolean jORTESubscriptionPropertiesSet(long subsHandle, SubsProp subProps);
211
212   private native
213   Status jORTESubscriptionGetStatus(long subsHandle);
214
215   private native
216   int jORTESubscriptionWaitForPublications(long subsHandle, 
217                                                NtpTime wait,
218                                                                    long retries,
219                                                                                    long noPublications);  
220   private native
221   int jORTESubscriptionPull(long subsHandle);  
222  
223   
224   
225 }
226