Log the queue size before and after journal rotation, to see if rotation is killing us.
[lwes-journaller.git] / src / queue_factory.c
blob845387171f704c1058891bf457913354f6545f33
1 /*======================================================================*
2 * Copyright (C) 2008 Light Weight Event System *
3 * All rights reserved. *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
18 * Boston, MA 02110-1301 USA. *
19 *======================================================================*/
21 #include "config.h"
23 #include "queue.h"
25 #include "queue_msg.h"
26 #include "queue_mqueue.h"
28 #include "log.h"
29 #include "opt.h"
31 #include <stdio.h>
32 #include <string.h>
33 #include <stdlib.h>
34 #include <dlfcn.h> // see http://www.tldp.org/HOWTO/C++-dlopen/index.html
36 int queue_factory (struct queue* this_queue)
38 /* Create queue object. */
39 if ( strcmp(arg_queue_type, ARG_MSG) == 0 )
41 if ( queue_msg_ctor(this_queue, arg_queue_name,
42 arg_queue_max_sz, arg_queue_max_cnt) < 0 )
44 LOG_ER("No SysV SHM support.\n");
45 return -1;
48 else if ( strcmp(arg_queue_type, ARG_MQ) == 0 )
50 if ( queue_mqueue_ctor(this_queue, arg_queue_name,
51 arg_queue_max_sz, arg_queue_max_cnt) < 0 )
53 LOG_ER("No POSIX mqueue support.\n");
54 return -1;
57 else
59 char pathname[256] ;
60 char *err = NULL ;
61 void* module = NULL ;
62 strcpy(pathname, "/home/y/lib/liblwes-journaller-queue-") ;
63 strcat(pathname, arg_queue_type) ;
64 strcat(pathname, ".so") ;
65 module = dlopen(pathname, RTLD_NOW) ;
67 if ( module )
69 char symname[100] ;
70 strcpy(symname, "lwes_journaller_queue_") ;
71 strcat(symname, arg_queue_type) ;
72 strcat(symname, "_LTX_init") ;
73 lwes_journaller_queue_init_t init =
74 (lwes_journaller_queue_init_t) dlsym(module, symname) ;
75 if ( !dlerror() )
77 if ( (*init)(this_queue, arg_queue_name,
78 arg_queue_max_sz, arg_queue_max_cnt) < 0 )
80 LOG_ER("Failed to create a dynamic queue method.\n") ;
81 return -1 ;
83 else
85 return 0 ;
88 else
90 err = dlerror() ;
93 else
95 err = dlerror() ;
97 LOG_ER("Unrecognized queue type '%s', try \"" ARG_MSG "\" or "
98 "\"" ARG_MQ "\".\n%s\n", arg_queue_type, err);
99 return -1;
102 return 0;