00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
| /* no_source_notify.c - see http://ultramessaging.github.io/UMExamples/no_source_notify/c/index.html
*
* Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved.
* Permission is granted to licensees to use
* or alter this software for any purpose, including commercial applications,
* according to the terms laid out in the Software License Agreement.
*
* This source code example is provided by Informatica for educational
* and evaluation purposes only.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES
* EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF
* NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
* PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE
* UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE
* LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR
* INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE
* TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF
* THE LIKELIHOOD OF SUCH DAMAGES.
*/
#include <stdio.h>
#if defined(_MSC_VER)
/* Windows-only includes */
#include <winsock2.h>
#define SLEEP(s) Sleep((s)*1000)
#else
/* Unix-only includes */
#include <stdlib.h>
#include <unistd.h>
#define SLEEP(s) sleep(s)
#endif
#include <lbm/lbm.h>
/* Example error checking macro. Include after each UM call. */
#define EX_LBM_CHK(err) do { \
if ((err) < 0) { \
fprintf(stderr, "%s:%d, lbm error: '%s'\n", \
__FILE__, __LINE__, lbm_errmsg()); \
exit(1); \
} \
} while (0)
#define NO_SOURCE_QUERIES "25"
int no_source = 0;
/* Callback used to handle request message for receiver */
int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd)
{
switch (msg->type) {
case LBM_MSG_NO_SOURCE_NOTIFICATION:
printf("[%s], no sources found for topic after %s queries\n", msg->topic_name, NO_SOURCE_QUERIES);
no_source++;
break;
default:
printf("Other event, type=%x\n", msg->type);
break;
}
return 0;
} /* rcv_handle_msg */
int main(int argc, char **argv)
{
lbm_context_t *ctx; /* Context object */
lbm_rcv_t *rcv; /* Receive object: for subscribing to topics. */
lbm_topic_t *rtopic; /* Receiver Topic object */
lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */
int err;
#if defined(_WIN32)
/* windows-specific code */
WSADATA wsadata;
int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata);
if (wsStat != 0)
{
printf("line %d: wsStat=%d\n",__LINE__,wsStat);
exit(1);
}
#endif
/* Initialize context atrributes and create context */
err = lbm_context_create(&ctx, NULL, NULL, NULL);
EX_LBM_CHK(err);
err = lbm_rcv_topic_attr_create(&rattr);
EX_LBM_CHK(err);
err = lbm_rcv_topic_attr_str_setopt(rattr, "resolution_no_source_notification_threshold", NO_SOURCE_QUERIES);
EX_LBM_CHK(err);
err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", rattr);
EX_LBM_CHK(err);
err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL);
EX_LBM_CHK(err);
while (!no_source) { }
err = lbm_rcv_delete(rcv);
EX_LBM_CHK(err);
err = lbm_context_delete(ctx);
EX_LBM_CHK(err);
#if defined(_MSC_VER)
/* Windows-specific cleanup overhead */
WSACleanup();
#endif
return 0;
} /* main */
|