01: /*
02: * DDS (Data Distribution Service) for JacORB
03: *
04: * Copyright (C) 2005 , Ahmed yehdih <ahmed.yehdih@gmail.com>, fouad
05: * allaoui <fouad.allaoui@gmail.com>, Didier Donsez (didier.donsez@ieee.org)
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Library General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU Library General Public License for more details.
16: *
17: * You should have received a copy of the GNU Library General Public
18: * License along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20: * 02111-1307, USA.
21: *
22: * Coontact: Ahmed yehdih <ahmed.yehdih@gmail.com>, fouad allaoui
23: * <fouad.allaoui@gmail.com>, Didier Donsez (didier.donsez@ieee.org)
24: * Contributor(s)
25: *
26: **/
27: package org.jacorb.dds;
28:
29: import java.lang.reflect.Method;
30:
31: import org.omg.CORBA.Any;
32: import org.omg.CosEventChannelAdmin.EventChannel;
33: import org.omg.CosEventChannelAdmin.EventChannelHelper;
34: import org.omg.CosEventChannelAdmin.ProxyPushConsumer;
35: import org.omg.CosEventChannelAdmin.SupplierAdmin;
36: import org.omg.CosEventComm.PushSupplierPOA;
37: import org.omg.CosNaming.NamingContextExt;
38: import org.omg.CosNaming.NamingContextExtHelper;
39: import org.omg.dds.Topic;
40: import org.omg.dds.TopicHelper;
41:
42: public class Supplier extends PushSupplierPOA {
43:
44: EventChannel e;
45: org.omg.CORBA.ORB orb;
46: org.omg.PortableServer.POA poa;
47: SupplierAdmin supplierAdmin;
48: ProxyPushConsumer proxyPushConsumer;
49:
50: public Supplier(org.omg.CORBA.ORB orb,
51: org.omg.PortableServer.POA poa) {
52: e = null;
53: this .orb = orb;
54: this .poa = poa;
55:
56: try {
57: NamingContextExt nc = NamingContextExtHelper.narrow(orb
58: .resolve_initial_references("NameService"));
59: e = EventChannelHelper.narrow(nc.resolve(nc
60: .to_name("eventchannel")));
61: supplierAdmin = e.for_suppliers();
62: proxyPushConsumer = supplierAdmin.obtain_push_consumer();
63: proxyPushConsumer.connect_push_supplier(_this (orb));
64: } catch (Exception ex) {
65: ex.printStackTrace();
66: }
67: }
68:
69: public void disconnect_push_supplier() {
70: System.out.println("Supplier disconnected");
71: }
72:
73: public synchronized void Write(Topic topic,
74: java.lang.Object instance) {
75: Class typehelper;
76: Class type_param_insert[] = new Class[2];
77: java.lang.Object valu_param_insert[] = new java.lang.Object[2];
78:
79: try {
80: Any any = orb.create_any();
81: TopicHelper.insert(any, topic);
82: proxyPushConsumer.push(any);
83: typehelper = Class
84: .forName(topic.get_type_name() + "Helper");
85: valu_param_insert[0] = any;
86: valu_param_insert[1] = instance;
87: type_param_insert[0] = Any.class;
88: type_param_insert[1] = Class.forName(topic.get_type_name());
89: Method Insert = typehelper.getMethod("insert",
90: type_param_insert);
91: Insert.invoke(null, valu_param_insert);
92: proxyPushConsumer.push(any);
93: } catch (Exception e) {
94: System.out.println("Exception : " + e);
95: e.printStackTrace();
96: }
97: }
98: }
|