Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.kevoree.library.camel.http;
  
 
 import java.util.List;
User: Erwan Daubert - erwan.daubert@gmail.com Date: 29/01/13 Time: 18:32

Author(s):
Erwan Daubert
Version:
1.0
 
         @DictionaryAttribute(name = "port", defaultValue = "10000", optional = true, fragmentDependant = true)
 })
 // TODO define upper bounds to 1
     private Random random = new Random();
 
     @Override
     protected void buildRoutes(RouteBuilder routeBuilder) {
         routeBuilder.from("kchannel:input")
                 .process(new Processor() {
                     @Override
                     public void process(Exchange exchangethrows Exception {
                         if (getBindedPorts().isEmpty() && getOtherFragments().isEmpty()) {
                             Log.debug("No consumer, msg lost=" + exchange.getIn().getBody());
                         } else {
                             // default behavior is round robin
                             int rang = .nextInt(getBindedPorts().size() + getOtherFragments().size());
                             Message message = (Messageexchange.getIn().getBody();
                             if (rang < getBindedPorts().size()) {
                                 Log.debug("select rang: {} for channel {}"rang + ""CamelJettyChannelService.this.getName());
                                 Log.debug("send message to {}"getBindedPorts().get(rang).getComponentName());
                                 Object result = forward(getBindedPorts().get(rang), message);
                                 // forward the result
                                 exchange.getOut().setBody(result);
                             } else {
                                 rang = rang - getBindedPorts().size();
                                 Log.debug("select rang: {} for channel {}"rang+""CamelJettyChannelService.this.getName());
                                 KevoreeChannelFragment cf = getOtherFragments().get(rang);
                                 Log.debug("Trying to send message on {}"getOtherFragments().get(rang).getNodeName());
                                 List<Stringaddresses = getAddresses(cf.getNodeName());
                                 if (addresses.size() > 0) {
                                     for (String address : addresses) {
                                         try {
                                             Object result = getContext().createProducerTemplate().requestBody("jetty:http://" + address + ":" + parsePortNumber(getOtherFragments().get(rang).getNodeName()), message);
                                             // forward the result
                                             exchange.getOut().setBody(result);
                                             break;
                                         } catch (Exception e) {
                                             Log.debug("Unable to send data to components on {} using {} as address",ecf.getNodeName(), "jetty:http://" + address + ":" + parsePortNumber(getOtherFragments().get(rang).getNodeName()));
                                         }
                                     }
                                 } else {
                                     try {
                                         Object result = getContext().createProducerTemplate().requestBody("jetty:http://127.0.0.1:" + parsePortNumber(getOtherFragments().get(rang).getNodeName()), message);
                                         // forward the result
                                         exchange.getOut().setBody(result);
                                     } catch (Exception e) {
                                         Log.debug("Unable to send data to components on {} using {} as address",ecf.getNodeName(), "jetty:http://127.0.0.1:" + parsePortNumber(getOtherFragments().get(rang).getNodeName()));
                                     }
                                 }
                             }
                         }
                     }
                 }
                 );
         List<Stringaddresses = getAddresses(getNodeName());
         if (addresses.size() > 0) {
             for (String address : addresses) {
                 try {
                     routeBuilder.from("jetty:http://:" + address + ).
                             process(new Processor() {
                                 public void process(Exchange exchangethrows Exception {
                                     // default behavior is round robin
                                     int rang = .nextInt(getBindedPorts().size());
                                     Log.debug("select rang: {} for channel {}"rang+""CamelJettyChannelService.this.getName());
                                     Log.debug("send message to {}"getBindedPorts().get(rang).getComponentName());
                                     Object result = forward(getBindedPorts().get(rang), (Messageexchange.getIn().getBody());
                                     // forward result
                                     exchange.getOut().setBody(result);
                                 }
                             });
                 } catch (Exception e) {
                     Log.debug("Fail to manage route {}",e"http://" + address + ":" + );
                 }
            }
        } else {
            try {
                routeBuilder.from("jetty:http://127.0.0.1:" + ).
                        process(new Processor() {
                            public void process(Exchange exchangethrows Exception {
                                // default behavior is round robin
                                int rang = .nextInt(getBindedPorts().size());
                                Log.debug("select rang: {} for channel {}",rang+""CamelJettyChannelService.this.getName());
                                Log.debug("send message to {}"getBindedPorts().get(rang).getComponentName());
                                Object result = forward(getBindedPorts().get(rang), (Messageexchange.getIn().getBody());
                                // forward result
                                exchange.getOut().setBody(result);
                            }
                        });
            } catch (Exception e) {
                Log.debug("Fail to manage route {}",e"http://127.0.0.1:" + );
            }
        }
    }
New to GrepCode? Check out our FAQ X