Package com.trendmicro.mist.client

Examples of com.trendmicro.mist.client.MistClient$MessagePair


            public void go() {
                go = true;
            }

            public void run() {
                MistClient sinkClient = null;
                try {
                    sinkClient = new MistClient(Role.PRODUCER, 1);
                    sinkClient.mount(true, fwdExchange.toString());
                    sinkClient.attach();
                }
                catch(Exception e) {
                    e.printStackTrace();
                    return;
                }

                if(fwdExchange.getBroker() == null) {
                    ready = true;
                    try {
                        sinkClient.close();
                    }
                    catch(Exception e) {
                        e.printStackTrace();
                    }
                    return;
                }

                javax.jms.Connection fromConn = null;
                javax.jms.Session fromSess = null;
                javax.jms.MessageConsumer fromConsumer = null;
                try {
                    ConnectionFactory fromFact = new com.sun.messaging.ConnectionFactory();
                    ((com.sun.messaging.ConnectionFactory) fromFact).setProperty(com.sun.messaging.ConnectionConfiguration.imqBrokerHostName, fwdExchange.getBroker());
                    ((com.sun.messaging.ConnectionFactory) fromFact).setProperty(com.sun.messaging.ConnectionConfiguration.imqBrokerHostPort, "7676");
                    ((com.sun.messaging.ConnectionFactory) fromFact).setProperty(com.sun.messaging.ConnectionConfiguration.imqDefaultUsername, "admin");
                    ((com.sun.messaging.ConnectionFactory) fromFact).setProperty(com.sun.messaging.ConnectionConfiguration.imqDefaultPassword, "admin");
                    fromConn = fromFact.createConnection();
                    fromConn.start();

                    fromSess = fromConn.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
                    javax.jms.Destination fromDest;
                    if(fwdExchange.isQueue())
                        fromDest = fromSess.createQueue(fwdExchange.getName());
                    else
                        fromDest = fromSess.createTopic(fwdExchange.getName());
                    fromConsumer = fromSess.createConsumer(fromDest);
                }
                catch(Exception e) {
                    e.printStackTrace();
                }
                ready = true;

                for(;;) {
                    if(!go) {
                        Utils.justSleep(100);
                    }
                    else
                        break;
                }

                while(!done) {
                    try {
                        javax.jms.Message msg = fromConsumer.receive(50);
                        if(msg != null) {
                            ByteArrayOutputStream bos = new ByteArrayOutputStream();
                            try {
                                if(msg instanceof BytesMessage) {
                                    byte[] buffer = new byte[256];
                                    int ret = -1;
                                    while((ret = ((BytesMessage) msg).readBytes(buffer)) > 0)
                                        bos.write(buffer, 0, ret);
                                }
                                else if(msg instanceof TextMessage) {
                                    byte[] buffer = ((TextMessage) msg).getText().getBytes("UTF-8");
                                    bos.write(buffer, 0, buffer.length);
                                }
                            }
                            catch(Exception e) {
                                e.printStackTrace();
                                continue;
                            }

                            byte[] buffer = bos.toByteArray();
                            MistMessage.MessageBlock.Builder msgBuilder = MistMessage.MessageBlock.newBuilder().setId(fwdExchange.toString()).setMessage(ByteString.copyFrom(buffer));
                            Enumeration<?> propNames = msg.getPropertyNames();
                            while(propNames.hasMoreElements()) {
                                String key = (String) propNames.nextElement();
                                String value = msg.getStringProperty(key);
                                if(key.equals("MIST_TTL"))
                                    msgBuilder.setTtl(Long.valueOf(value));
                                else
                                    msgBuilder.addProperties(KeyValuePair.newBuilder().setKey(key).setValue(value).build());
                            }
                            sinkClient.writeMessage(msgBuilder.build());
                            totalForwardedCount++;
                        }
                    }
                    catch(Exception e) {
                        e.printStackTrace();
                    }
                }

                try {
                    fromConsumer.close();
                    fromSess.close();
                    fromConn.close();

                    sinkClient.close();
                }
                catch(Exception e) {
                    e.printStackTrace();
                }
            }
View Full Code Here

TOP

Related Classes of com.trendmicro.mist.client.MistClient$MessagePair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.