Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) FuseSource, Inc. http://fusesource.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.fusesource.fabric.stream.log;
 
 

Author(s):
Hiram Chirino
 
 public class LogStreamProducer {
     
     private String broker;
     private String destination;
     private int batchSize = 1024*64;
     private long batchTimeout = 1000*5;
     private boolean compress = true;
     private InputStream is = .;
 
     public static void main(String[] argsthrows Exception {
         LogStreamProducer producer = new LogStreamProducer();
         
         // Process the arguments
         LinkedList<Stringargl = new LinkedList<String>(Arrays.asList(args));
         while(!argl.isEmpty()) {
             try {
                 String arg = argl.removeFirst();
                 if"--help".equals(arg) ) {
                     displayHelpAndExit(0);
                 } else if"--broker".equals(arg) ) {
                     producer.broker = shift(argl);
                 } else if"--destination".equals(arg) ) {
                     producer.destination = shift(argl);
                 } else if"--batch-size".equals(arg) ) {
                     producer.batchSize = Integer.parseInt(shift(argl));
                 } else if"--batch-timeout".equals(arg) ) {
                     producer.batchTimeout =  Long.parseLong(shift(argl));
                 } else if"--compress".equals(arg) ) {
                     producer.compress = Boolean.parseBoolean(shift(argl));
                 } else {
                     ..println("Invalid usage: unknown option: "+arg);
                     displayHelpAndExit(1);
                 }
             } catch (NumberFormatException e) {
                 ..println("Invalid usage: argument not a number");
                 displayHelpAndExit(1);
             }
         }
         ifproducer.broker==null ) {
             ..println("Invalid usage: --broker option not specified.");
             displayHelpAndExit(1);
         }
         ifproducer.destination==null ) {
             ..println("Invalid usage: --destination option not specified.");
             displayHelpAndExit(1);
         }
 
         producer.execute();
         System.exit(0);
     }
 
     private static String shift(LinkedList<Stringargl) {
         if(argl.isEmpty()) {
             ..println("Invalid usage: Missing argument");
             displayHelpAndExit(1);
         }
         return argl.removeFirst();
     }
 
     private static void displayHelpAndExit(int exitCode) {
         System.exit(exitCode);
     }
 
    private void execute() throws Exception {
        CamelContext context = new DefaultCamelContext();
        configure(context);
        context.start();
        // block until the process is killed.
        synchronized (this) {
            while(true) {
                this.wait();
            }
        }
    }
    public void configure(CamelContext contextthrows Exception {
        // no need to use JMX for this embedded CamelContext
        context.disableJMX();
        context.addComponent("activemq", ActiveMQComponent.activeMQComponent());
        final InputBatcher batcher = new InputBatcher();
        batcher.setBatchSize();
        batcher.setBatchTimeout();
        batcher.setIs();
        context.addComponent("batcher"batcher);
        context.addRoutes(new RouteBuilder() {
            public void configure() throws Exception {
                Endpoint source = batcher.createEndpoint("stdin");
                RouteDefinition route = from(source);
                if() {
                    route = route.process(new SnappyCompressor());
                }
                route.to("activemq:"+);
            }
        });
    }
    public int getBatchSize() {
        return ;
    }
    public void setBatchSize(int batchSize) {
        this. = batchSize;
    }
    public long getBatchTimeout() {
        return ;
    }
    public void setBatchTimeout(long batchTimeout) {
        this. = batchTimeout;
    }
    public String getBroker() {
        return ;
    }
    public void setBroker(String broker) {
        this. = broker;
    }
    public boolean isCompress() {
        return ;
    }
    public void setCompress(boolean compress) {
        this. = compress;
    }
    public String getDestination() {
        return ;
    }
    public void setDestination(String destination) {
        this. = destination;
    }
    public InputStream getIs() {
        return ;
    }
    public void setIs(InputStream is) {
        this. = is;
    }
New to GrepCode? Check out our FAQ X