Tang Cheng | 31b9525 | 2014-10-23 09:22:35 +0800 | [diff] [blame^] | 1 | /* Copyright (c) 2002, 2005, Oracle. All rights reserved. */ |
| 2 | |
| 3 | /* |
| 4 | NAME |
| 5 | occiAQ.h - Header file for occi AQ classes |
| 6 | |
| 7 | DESCRIPTION |
| 8 | Class declarations for Producer, Consumer, Message, Agent |
| 9 | Listener, Subscription |
| 10 | |
| 11 | RELATED DOCUMENTS |
| 12 | <note any documents related to this facility> |
| 13 | |
| 14 | EXPORT FUNCTION(S) |
| 15 | <external functions declared for use outside package - one-line |
| 16 | descriptions> |
| 17 | |
| 18 | INTERNAL FUNCTION(S) |
| 19 | <other external functions declared - one-line descriptions> |
| 20 | |
| 21 | EXAMPLES |
| 22 | |
| 23 | NOTES |
| 24 | <other useful comments, qualifications, etc.> |
| 25 | |
| 26 | MODIFIED (MM/DD/YY) |
| 27 | cparampa 10/12/02 - creation |
| 28 | |
| 29 | */ |
| 30 | |
| 31 | #ifndef _olint /* disable olint check */ |
| 32 | |
| 33 | #ifndef OCCIAQ_ORACLE |
| 34 | # define OCCIAQ_ORACLE |
| 35 | |
| 36 | #ifndef OCCICOMMON_ORACLE |
| 37 | #include <occiCommon.h> |
| 38 | #endif |
| 39 | |
| 40 | namespace oracle { |
| 41 | namespace occi { |
| 42 | namespace aq{ |
| 43 | |
| 44 | /*--------------------------------------------------------------------------- |
| 45 | PUBLIC TYPES AND CONSTANTS |
| 46 | ---------------------------------------------------------------------------*/ |
| 47 | |
| 48 | class Message |
| 49 | { |
| 50 | public: |
| 51 | |
| 52 | enum MessageState |
| 53 | { |
| 54 | MSG_READY = OCI_MSG_READY, |
| 55 | MSG_WAITING = OCI_MSG_WAITING, |
| 56 | MSG_PROCESSED = OCI_MSG_PROCESSED, |
| 57 | MSG_EXPIRED = OCI_MSG_EXPIRED |
| 58 | }; |
| 59 | enum PayloadType |
| 60 | { |
| 61 | RAW, |
| 62 | ANYDATA, |
| 63 | OBJECT |
| 64 | }; |
| 65 | |
| 66 | Message( const Environment *env ); |
| 67 | Message( const Message& rhs); |
| 68 | ~Message(); |
| 69 | |
| 70 | void operator=(const Message& rhs); |
| 71 | int getAttemptsToDequeue() const ; |
| 72 | void setCorrelationId( const OCCI_STD_NAMESPACE::string& corr_id ) ; |
| 73 | OCCI_STD_NAMESPACE::string getCorrelationId() const ; |
| 74 | void setDelay( int delay ) ; |
| 75 | int getDelay() const ; |
| 76 | Date getMessageEnqueuedTime() const ; |
| 77 | void setExceptionQueueName( const OCCI_STD_NAMESPACE::string& queue ) ; |
| 78 | OCCI_STD_NAMESPACE::string getExceptionQueueName() const ; |
| 79 | void setExpiration( int exp ) ; |
| 80 | int getExpiration() const ; |
| 81 | MessageState getMessageState() const ; |
| 82 | void setPriority( int priority ) ; |
| 83 | int getPriority() const ; |
| 84 | void setRecipientList( OCCI_STD_NAMESPACE::vector<Agent>& ag_list ) ; |
| 85 | void setSenderId( const Agent& sender ) ; |
| 86 | Agent getSenderId() const ; |
| 87 | void setOriginalMessageId( const Bytes& queue ) ; |
| 88 | Bytes getOriginalMessageId() const ; |
| 89 | void setNull(); |
| 90 | bool isNull() const; |
| 91 | |
| 92 | void setBytes( const Bytes& bytes); |
| 93 | void setObject( PObject* pobj); |
| 94 | void setAnyData( const AnyData& any); |
| 95 | |
| 96 | Bytes getBytes() const ; |
| 97 | PObject *getObject() ; |
| 98 | AnyData getAnyData() const ; |
| 99 | |
| 100 | PayloadType getPayloadType( ) const; |
| 101 | |
| 102 | private: |
| 103 | Ptr<MessageImpl> ptr; |
| 104 | OCIAQMsgProperties* getOCIMsgProperties() const; |
| 105 | Message( const Environment *env, const Connection *con, |
| 106 | OCIAQMsgProperties *msgprop, void *data, unsigned int dataLen, |
| 107 | bool isNull, PayloadType pType); |
| 108 | friend class ConsumerImpl; |
| 109 | friend class ProducerImpl; |
| 110 | friend class NotifyResult; |
| 111 | }; |
| 112 | |
| 113 | class Producer |
| 114 | { |
| 115 | public: |
| 116 | |
| 117 | enum EnqueueSequence |
| 118 | { |
| 119 | ENQ_BEFORE = OCI_ENQ_BEFORE, |
| 120 | ENQ_TOP = OCI_ENQ_TOP |
| 121 | }; |
| 122 | enum Visibility |
| 123 | { |
| 124 | ENQ_IMMEDIATE = OCI_ENQ_IMMEDIATE, |
| 125 | ENQ_ON_COMMIT = OCI_ENQ_ON_COMMIT |
| 126 | }; |
| 127 | |
| 128 | Producer( const Connection *conn ); |
| 129 | Producer( const Connection *conn, |
| 130 | const OCCI_STD_NAMESPACE::string& queue ); |
| 131 | Producer( const Producer& rhs); |
| 132 | ~Producer(); |
| 133 | |
| 134 | void operator=(const Producer& prod); |
| 135 | void setRelativeMessageId( const Bytes& msgid ); |
| 136 | Bytes getRelativeMessageId() const; |
| 137 | void setSequenceDeviation( EnqueueSequence option ); |
| 138 | EnqueueSequence getSequenceDeviation() const; |
| 139 | void setVisibility( Visibility option ); |
| 140 | Visibility getVisibility() const; |
| 141 | void setQueueName( const OCCI_STD_NAMESPACE::string& queue ); |
| 142 | OCCI_STD_NAMESPACE::string getQueueName() const; |
| 143 | void setTransformation( const OCCI_STD_NAMESPACE::string& fName); |
| 144 | OCCI_STD_NAMESPACE::string getTransformation() const; |
| 145 | Bytes send( Message& msg, const OCCI_STD_NAMESPACE::string& queue ); |
| 146 | Bytes send( Message& msg ); |
| 147 | void setNull(); |
| 148 | bool isNull() const; |
| 149 | |
| 150 | private: |
| 151 | Ptr<ProducerImpl> ptr; |
| 152 | }; |
| 153 | |
| 154 | class Consumer |
| 155 | { |
| 156 | public: |
| 157 | |
| 158 | enum DequeueMode |
| 159 | { |
| 160 | DEQ_BROWSE = OCI_DEQ_BROWSE, |
| 161 | DEQ_LOCKED = OCI_DEQ_LOCKED, |
| 162 | DEQ_REMOVE = OCI_DEQ_REMOVE, |
| 163 | DEQ_REMOVE_NODATA = OCI_DEQ_REMOVE_NODATA |
| 164 | }; |
| 165 | enum Navigation |
| 166 | { |
| 167 | DEQ_FIRST_MSG = OCI_DEQ_FIRST_MSG, |
| 168 | DEQ_NEXT_TRANSACTION = OCI_DEQ_NEXT_TRANSACTION, |
| 169 | DEQ_NEXT_MSG = OCI_DEQ_NEXT_MSG |
| 170 | }; |
| 171 | enum Visibility |
| 172 | { |
| 173 | DEQ_IMMEDIATE = OCI_DEQ_IMMEDIATE, |
| 174 | DEQ_ON_COMMIT = OCI_DEQ_ON_COMMIT |
| 175 | }; |
| 176 | enum |
| 177 | { |
| 178 | DEQ_WAIT_FOREVER = OCI_DEQ_WAIT_FOREVER, |
| 179 | DEQ_NO_WAIT = OCI_DEQ_NO_WAIT |
| 180 | }; |
| 181 | |
| 182 | Consumer( const Connection *conn ); |
| 183 | Consumer( const Connection * conn, const Agent& agent); |
| 184 | Consumer( const Connection *conn, |
| 185 | const OCCI_STD_NAMESPACE::string& queue ); |
| 186 | Consumer(const Consumer& con); |
| 187 | ~Consumer(); |
| 188 | |
| 189 | void operator=(const Consumer& con); |
| 190 | void setAgent(const Agent& agent); |
| 191 | void setConsumerName( const OCCI_STD_NAMESPACE::string& name ); |
| 192 | OCCI_STD_NAMESPACE::string getConsumerName() const; |
| 193 | void setCorrelationId( const OCCI_STD_NAMESPACE::string& cor_id ); |
| 194 | OCCI_STD_NAMESPACE::string getCorrelationId() const; |
| 195 | void setDequeueMode( DequeueMode mode ); |
| 196 | DequeueMode getDequeueMode() const; |
| 197 | void setMessageIdToDequeue( const Bytes& msgid ); |
| 198 | Bytes getMessageIdToDequeue() const; |
| 199 | void setPositionOfMessage( Navigation pos ); |
| 200 | Navigation getPositionOfMessage() const; |
| 201 | void setVisibility( Visibility option ); |
| 202 | Visibility getVisibility() const; |
| 203 | void setWaitTime( unsigned int wait ); |
| 204 | unsigned int getWaitTime() const; |
| 205 | void setQueueName( const OCCI_STD_NAMESPACE::string& queue ); |
| 206 | OCCI_STD_NAMESPACE::string getQueueName() const; |
| 207 | void setTransformation( const OCCI_STD_NAMESPACE::string& fName); |
| 208 | OCCI_STD_NAMESPACE::string getTransformation() const; |
| 209 | Message receive( Message::PayloadType pType, |
| 210 | const OCCI_STD_NAMESPACE::string& type="", |
| 211 | const OCCI_STD_NAMESPACE::string& schema=""); |
| 212 | void setNull(); |
| 213 | bool isNull() const; |
| 214 | |
| 215 | private: |
| 216 | Ptr<ConsumerImpl> ptr; |
| 217 | }; |
| 218 | |
| 219 | class Agent |
| 220 | { |
| 221 | public: |
| 222 | Agent( const Environment *env ); |
| 223 | Agent( const Environment *env, |
| 224 | const OCCI_STD_NAMESPACE::string& name, |
| 225 | const OCCI_STD_NAMESPACE::string& address, |
| 226 | unsigned int protocol=0 ) ; |
| 227 | Agent(const Agent& a); |
| 228 | ~Agent() ; |
| 229 | |
| 230 | void operator=(const Agent& a); |
| 231 | void setName( const OCCI_STD_NAMESPACE::string& name ); |
| 232 | OCCI_STD_NAMESPACE::string getName() const; |
| 233 | void setAddress( const OCCI_STD_NAMESPACE::string& addr ); |
| 234 | OCCI_STD_NAMESPACE::string getAddress() const; |
| 235 | void setProtocol(unsigned int protocol = 0); |
| 236 | unsigned int getProtocol() const; |
| 237 | void setNull(); |
| 238 | bool isNull() const; |
| 239 | OCIAQAgent* getOCIAQAgent() const; |
| 240 | |
| 241 | private: |
| 242 | Ptr<AgentImpl> ptr; |
| 243 | Agent( const Environment *env, OCIAQAgent *rhs, bool toFree = false ); |
| 244 | friend class Listener; |
| 245 | friend class MessageImpl; |
| 246 | }; |
| 247 | |
| 248 | class Listener |
| 249 | { |
| 250 | public: |
| 251 | Listener( const Connection *conn ); |
| 252 | Listener( const Connection *conn, |
| 253 | OCCI_STD_NAMESPACE::vector<Agent> &agList, |
| 254 | int waitTime=0 ); |
| 255 | ~Listener(); |
| 256 | |
| 257 | Agent listen(); |
| 258 | void setAgentList(OCCI_STD_NAMESPACE::vector<Agent> &agList); |
| 259 | void setTimeOutForListen(int waitTime); |
| 260 | OCCI_STD_NAMESPACE::vector<Agent> getAgentList() const; |
| 261 | int getTimeOutForListen() const; |
| 262 | |
| 263 | private: |
| 264 | const ConnectionImpl *conn; |
| 265 | OCIAQAgent** agentList; |
| 266 | unsigned int numAgents; |
| 267 | int timeOut; |
| 268 | void *listenerExt; |
| 269 | }; |
| 270 | |
| 271 | |
| 272 | class Subscription |
| 273 | { |
| 274 | public: |
| 275 | enum Presentation |
| 276 | { |
| 277 | PRES_DEFAULT = OCI_SUBSCR_PRES_DEFAULT, |
| 278 | PRES_XML = OCI_SUBSCR_PRES_XML |
| 279 | }; |
| 280 | enum Protocol |
| 281 | { |
| 282 | PROTO_CBK = OCI_SUBSCR_PROTO_OCI, |
| 283 | PROTO_MAIL = OCI_SUBSCR_PROTO_MAIL, |
| 284 | PROTO_SERVER = OCI_SUBSCR_PROTO_SERVER, |
| 285 | PROTO_HTTP = OCI_SUBSCR_PROTO_HTTP |
| 286 | }; |
| 287 | enum Namespace |
| 288 | { |
| 289 | NS_ANONYMOUS = OCI_SUBSCR_NAMESPACE_ANONYMOUS, |
| 290 | NS_AQ = OCI_SUBSCR_NAMESPACE_AQ |
| 291 | }; |
| 292 | |
| 293 | Subscription(const Environment* env); |
| 294 | Subscription(const Environment* env, OCISubscription* sub); |
| 295 | Subscription(const Subscription& sub); |
| 296 | ~Subscription(); |
| 297 | |
| 298 | void operator=(const Subscription& sub); |
| 299 | unsigned int getDatabaseServersCount() const; |
| 300 | void setDatabaseServerNames( |
| 301 | const OCCI_STD_NAMESPACE::vector<OCCI_STD_NAMESPACE::string>& dbsrv); |
| 302 | OCCI_STD_NAMESPACE::vector<OCCI_STD_NAMESPACE::string> |
| 303 | getDatabaseServerNames() const ; |
| 304 | void setNotifyCallback(unsigned int (*callback)(Subscription& sub, |
| 305 | NotifyResult *nr)); |
| 306 | unsigned int (*getNotifyCallback() const)(Subscription& sub, |
| 307 | NotifyResult *nr); |
| 308 | void setCallbackContext(void* ctx); |
| 309 | void* getCallbackContext() const; |
| 310 | void setSubscriptionName(const OCCI_STD_NAMESPACE::string& name); |
| 311 | OCCI_STD_NAMESPACE::string getSubscriptionName() const ; |
| 312 | void setSubscriptionNamespace(Namespace nameSpace); |
| 313 | Namespace getSubscriptionNamespace() const ; |
| 314 | void setPayload(const Bytes& payload); |
| 315 | Bytes getPayload() const ; |
| 316 | void setRecipientName( const OCCI_STD_NAMESPACE::string& name); |
| 317 | OCCI_STD_NAMESPACE::string getRecipientName() const; |
| 318 | void setPresentation( Presentation pres) ; |
| 319 | Presentation getPresentation() const ; |
| 320 | void setProtocol( Protocol prot) ; |
| 321 | Protocol getProtocol() const ; |
| 322 | OCISubscription* getOCISubscription() const; |
| 323 | void setNull(); |
| 324 | bool isNull() const; |
| 325 | Environment* getEnvironment() const; |
| 326 | |
| 327 | private: |
| 328 | Ptr<SubscriptionImpl> ptr; |
| 329 | }; |
| 330 | |
| 331 | class NotifyResult |
| 332 | { |
| 333 | public: |
| 334 | Bytes getPayload() const; |
| 335 | Message getMessage() const; |
| 336 | Bytes getMessageId() const; |
| 337 | OCCI_STD_NAMESPACE::string getConsumerName() const; |
| 338 | OCCI_STD_NAMESPACE::string getQueueName() const; |
| 339 | |
| 340 | private: |
| 341 | const EnvironmentImpl *env; |
| 342 | void *payload; |
| 343 | unsigned int payloadLen; |
| 344 | void *desc; |
| 345 | ub4 mode; |
| 346 | void *notifyResultExt; |
| 347 | |
| 348 | //private constructor |
| 349 | NotifyResult(const Environment *env, void *payload, ub4 payloadLen, |
| 350 | void *pdescriptor, ub4 mode); |
| 351 | |
| 352 | friend class SubscriptionImpl; |
| 353 | }; |
| 354 | |
| 355 | /*--------------------------------------------------------------------------- |
| 356 | PRIVATE TYPES AND CONSTANTS |
| 357 | ---------------------------------------------------------------------------*/ |
| 358 | |
| 359 | |
| 360 | /*--------------------------------------------------------------------------- |
| 361 | EXPORT FUNCTIONS |
| 362 | ---------------------------------------------------------------------------*/ |
| 363 | |
| 364 | |
| 365 | /*--------------------------------------------------------------------------- |
| 366 | INTERNAL FUNCTIONS |
| 367 | ---------------------------------------------------------------------------*/ |
| 368 | } /* end of namespace aq */ |
| 369 | } /* end of namespace occi */ |
| 370 | } /* end of namespace oracle */ |
| 371 | |
| 372 | #endif /* OCCIAQ_ORACLE */ |
| 373 | |
| 374 | #endif /* _olint */ |