Example usage for org.springframework.context ApplicationContext getBean

List of usage examples for org.springframework.context ApplicationContext getBean

Introduction

In this page you can find the example usage for org.springframework.context ApplicationContext getBean.

Prototype

Object getBean(String name) throws BeansException;

Source Link

Document

Return an instance, which may be shared or independent, of the specified bean.

Usage

From source file:koper.demo.performance.KafkaReceiverPerf.java

/**
 * ??/*w  w  w.  ja va2s  .  c o m*/
 * @param args : ?(?)????
 */
public static void main(String[] args) {
    final ApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:kafka/context-data-consumer.xml");

    if (args.length > 0) {
        int statLine = Integer.parseInt(args[0]);
        OrderListener listener = context.getBean(OrderListener.class);
        listener.changeStatLine(statLine);
    }

    final ConsumerLauncher consumerLauncher = context.getBean(ConsumerLauncher.class);
    // we have close the switch in context-data-consumer.xml profile(autoStart) temporary
    consumerLauncher.start();

    logger.info("KafkaReceiverPerf started!");
}

From source file:stormy.pythian.sandbox.SandBox.java

public static void main(String[] args) {
    ApplicationContext context = new AnnotationConfigApplicationContext(CoreConfiguration.class);
    ComponentDescriptionFactory componentDescriptionFactory = context
            .getBean(ComponentDescriptionFactory.class);
    PythianStateDescriptionFactory stateDescriptionFactory = context
            .getBean(PythianStateDescriptionFactory.class);

    PythianStateDescription inMemoryDescription = stateDescriptionFactory
            .createDescription(InMemoryPythianState.class);
    ComponentDescription randomWordSource = componentDescriptionFactory
            .createDescription(RandomWordSource.class);
    ComponentConfiguration randomWordSourceConfiguration = new ComponentConfiguration(randomAlphabetic(6),
            randomWordSource);/*from  w ww . j  a v  a 2 s  .c om*/
    randomWordSourceConfiguration.add(new OutputStreamConfiguration(randomWordSource.getOutputStreams().get(0),
            createMappings(RandomWordSource.WORD_FEATURE, "random word")));

    ComponentDescription wordCount = componentDescriptionFactory.createDescription(WordCount.class);
    ComponentConfiguration wordCountConfiguration = new ComponentConfiguration(randomAlphabetic(6), wordCount);
    wordCountConfiguration.add(new InputStreamConfiguration(wordCount.getInputStreams().get(0),
            createMappings(WordCount.WORD_FEATURE, "random word")));
    wordCountConfiguration.add(new OutputStreamConfiguration(wordCount.getOutputStreams().get(0),
            createMappings(WordCount.COUNT_FEATURE, "word count")));
    wordCountConfiguration.add(stateConfiguration(inMemoryDescription).name("count state")
            .with("Transaction mode", NONE).with("Name", "Word count").build());

    ComponentDescription consoleOutput = componentDescriptionFactory.createDescription(ConsoleOutput.class);
    ComponentConfiguration consoleOutputConfiguration = new ComponentConfiguration(randomAlphabetic(6),
            consoleOutput);
    consoleOutputConfiguration.add(new InputStreamConfiguration(consoleOutput.getInputStreams().get(0),
            Arrays.asList("random word", "word count")));

    LocalCluster cluster = new LocalCluster();

    PythianToplogyConfiguration topologyConfiguration = new PythianToplogyConfiguration();
    topologyConfiguration.add(randomWordSourceConfiguration);
    topologyConfiguration.add(wordCountConfiguration);
    topologyConfiguration.add(consoleOutputConfiguration);

    topologyConfiguration.add(new ConnectionConfiguration(randomWordSourceConfiguration.getId(), "out",
            wordCountConfiguration.getId(), "in"));
    topologyConfiguration.add(new ConnectionConfiguration(wordCountConfiguration.getId(), "out",
            consoleOutputConfiguration.getId(), "in"));

    try {
        PythianTopology pythianTopology = new PythianTopology();
        pythianTopology.build(topologyConfiguration);

        cluster.submitTopology(SandBox.class.getSimpleName(), pythianTopology.getTridentConfig(),
                pythianTopology.getStormTopology());

        Utils.sleep(120000);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        cluster.shutdown();
    }

}

From source file:com.mvdb.etl.actions.ModifyCustomerData.java

public static void main(String[] args) {

    ActionUtils.assertEnvironmentSetupOk();
    ActionUtils.assertFileExists("~/.mvdb", "~/.mvdb missing. Existing.");
    ActionUtils.assertFileExists("~/.mvdb/status.InitCustomerData.complete",
            "300init-customer-data.sh not executed yet. Exiting");
    //This check is not required as data can be modified any number of times
    //ActionUtils.assertFileDoesNotExist("~/.mvdb/status.ModifyCustomerData.complete", "ModifyCustomerData already done. Start with 100init.sh if required. Exiting");
    ActionUtils.setUpInitFileProperty();
    ActionUtils.createMarkerFile("~/.mvdb/status.ModifyCustomerData.start", true);

    String customerName = null;/*www  .  j  a  va2 s  . c o  m*/
    //Date startDate  = null;
    //Date endDate  = null;
    final CommandLineParser cmdLinePosixParser = new PosixParser();
    final Options posixOptions = constructPosixOptions();
    CommandLine commandLine;
    try {
        commandLine = cmdLinePosixParser.parse(posixOptions, args);
        //            if (commandLine.hasOption("startDate"))
        //            {
        //                String startDateStr = commandLine.getOptionValue("startDate");
        //                startDate = ActionUtils.getDate(startDateStr);
        //            }
        //            if (commandLine.hasOption("endDate"))
        //            {
        //                String endDateStr = commandLine.getOptionValue("endDate");
        //                endDate = ActionUtils.getDate(endDateStr);
        //            }
        if (commandLine.hasOption("customerName")) {
            customerName = commandLine.getOptionValue("customerName");
        }
    } catch (ParseException parseException) // checked exception
    {
        System.err.println(
                "Encountered exception while parsing using PosixParser:\n" + parseException.getMessage());
    }

    if (customerName == null) {
        System.err.println("customerName has not been specified.  Aborting...");
        System.exit(1);
    }

    //        if (startDate == null)
    //        {
    //            System.err.println("startDate has not been specified with the correct format YYYYMMddHHmmss.  Aborting...");
    //            System.exit(1);
    //        }
    //        
    //        if (endDate == null)
    //        {
    //            System.err.println("endDate has not been specified with the correct format YYYYMMddHHmmss.  Aborting...");
    //            System.exit(1);
    //        }
    //        
    //        if (endDate.after(startDate) == false)
    //        {
    //            System.err.println("endDate must be after startDate.  Aborting...");
    //            System.exit(1);
    //        }

    ApplicationContext context = Top.getContext();

    final OrderDAO orderDAO = (OrderDAO) context.getBean("orderDAO");

    long maxId = orderDAO.findMaxId();
    long totalOrders = orderDAO.findTotalOrders();

    long modifyCount = (long) (totalOrders * 0.1);

    String lastUsedEndTimeStr = ActionUtils.getConfigurationValue(customerName,
            ConfigurationKeys.LAST_USED_END_TIME);
    long lastUsedEndTime = Long.parseLong(lastUsedEndTimeStr);
    Date startDate1 = new Date();
    startDate1.setTime(lastUsedEndTime + 1000 * 60 * 60 * 24 * 1);
    Date endDate1 = new Date(startDate1.getTime() + 1000 * 60 * 60 * 24 * 1);

    for (int i = 0; i < modifyCount; i++) {
        Date updateDate = RandomUtil.getRandomDateInRange(startDate1, endDate1);
        long orderId = (long) Math.floor((Math.random() * maxId)) + 1L;
        logger.info("Modify Id " + orderId + " in orders");
        Order theOrder = orderDAO.findByOrderId(orderId);
        //             System.out.println("theOrder : " + theOrder);
        theOrder.setNote(RandomUtil.getRandomString(4));
        theOrder.setUpdateTime(updateDate);
        theOrder.setSaleCode(RandomUtil.getRandomInt());
        orderDAO.update(theOrder);
        //             System.out.println("theOrder Modified: " + theOrder);

    }
    ActionUtils.setConfigurationValue(customerName, ConfigurationKeys.LAST_USED_END_TIME,
            String.valueOf(endDate1.getTime()));
    logger.info("Modified " + modifyCount + " orders");
    ActionUtils.createMarkerFile("~/.mvdb/status.ModifyCustomerData.complete", true);
}

From source file:net.wessendorf.amqp.Main.java

public static void main(String[] args) {
    // get access to the Java based config
    ApplicationContext context = new AnnotationConfigApplicationContext(RabbitConfiguration.class);

    // get our service class
    // could use the @Named "rabbitPublishService" value as well, but this would require a type-cast.......
    RabbitPublishService rps = context.getBean(RabbitPublishService.class);

    // launch it!
    rps.run();//from  w  ww.j  a  v  a  2  s .c  o  m

    // System.exit(0);
}

From source file:org.ala.util.PartialIndex.java

public static void main(String[] args) throws Exception {
    ApplicationContext context = SpringUtils.getContext();
    PartialIndex loader = context.getBean(PartialIndex.class);

    try {/*from w w  w  . j av a 2s  .c  o m*/
        if (args.length != 1) {
            System.out.println("Please provide a file with a list of lsid....");
            System.exit(0);
        }
        loader.process(args[0]);
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(e);
        System.exit(0);
    }
    //System.exit(0);   
}

From source file:org.mshariq.cxf.brave.Client.java

public static void main(String args[]) throws Exception {

    OkHttpSender sender = OkHttpSender.create("http://127.0.0.1:9411/api/v1/spans");
    AsyncReporter<Span> reporter = AsyncReporter.builder(sender).build();
    Brave brave = new Brave.Builder("clientNew").reporter(reporter).build();
    final BraveClientProvider provider = new BraveClientProvider(brave);

    final Response response = WebClient.create("http://localhost:9000/catalog/2", Arrays.asList(provider))
            .accept(MediaType.APPLICATION_JSON).get();

    ApplicationContext appctxt = new ClassPathXmlApplicationContext(
            Client.class.getResource("/context-client.xml").toString());

    System.out.println("Client ready...");
    SampleInterface client = (SampleInterface) appctxt.getBean("sampleClient");
    System.out.println(client.getItems(0));
    response.close();/*from  ww  w  . j  a v  a 2s  .  c om*/
    reporter.close();
    sender.close();

    //  Thread.sleep(5 * 6000 * 1000);
    System.out.println("Server exiting");
    System.exit(0);
}

From source file:com.codekul.simpleboot.Main.java

public static void main(String[] args) throws Exception {

    ApplicationContext context = SpringApplication.run(Main.class, args);

    for (String bean : context.getBeanDefinitionNames()) {

        System.out.println("com.codekul.simpleboot.Main.main() Beans -> " + bean);
    }/*from   ww  w. j  a  v a 2  s  . c om*/

    Car car = (Car) context.getBean("carMy");
    car.setCarCity("Pune");
    car.setCarName("AUdi");

    System.out.println("Car is -> " + car.toString());

    Animal animal = (Animal) context.getBean("animal");
    animal.setCarMy(car);

    animal.setCountry("india");
    System.out.println("Animal Country - " + animal.getCountry());

    Car myCar = new Car(car);

    ObjectMapper objectMapper = new ObjectMapper();
    String carJson = objectMapper.writeValueAsString(myCar);

    System.out.println("Car JSON - " + carJson);
}

From source file:org.ala.hbase.IrmngDataLoader.java

public static void main(String[] args) throws Exception {
    ApplicationContext context = SpringUtils.getContext();
    IrmngDataLoader l = context.getBean(IrmngDataLoader.class);
    l.load();//from  w w w. j  a  va2s.c  om
    System.exit(1);
}

From source file:org.berlin.crawl.util.AddNewSeedsMain.java

public static void main(final String[] args) {
    logger.info("Running");
    final ApplicationContext ctx = new ClassPathXmlApplicationContext(
            "/org/berlin/batch/batch-databot-context.xml");
    final BotCrawlerDAO dao = new BotCrawlerDAO();
    final SessionFactory sf = (SessionFactory) ctx.getBean("sessionFactory");
    Session session = sf.openSession();/*from w w w  .  j a  va 2 s  .  c o m*/
    dao.createSeed(session, seed());
    final List<BotSeed> seeds = dao.findSeedRequests(session);
    for (final BotSeed seed : seeds) {
        System.out.println(seed);
    }
    if (session != null) {
        // May not need to close the session
        session.close();
    } // End of the if //
    logger.info("Done");
}

From source file:streaming.gui.PrincipaleJFrame.java

public static void main(String args[]) {

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            String file1 = "file:/C:\\Users\\ajc\\Documents\\NetBeansProjects\\Streaming\\application-context.xml";
            String file2 = "file:/C:\\Users\\admin\\Desktop\\Projets\\Streaming\\application-context.xml";

            ApplicationContext context = new FileSystemXmlApplicationContext(file2);
            JFrame jf = context.getBean(PrincipaleJFrame.class);
            jf.setSize(800, 600);//from  w w w .ja  v a  2  s.c o  m
            jf.setVisible(true);

        }
    });
}