Package hellovertx

Source Code of hellovertx.HelloVertx

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package hellovertx;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
import org.vertx.java.core.MultiMap;
import org.vertx.java.core.Vertx;
import org.vertx.java.core.VertxFactory;
import org.vertx.java.core.http.HttpServerRequest;

/**
*
* @author Shadowbring
*/
public class HelloVertx {

    public static void main(String[] args) throws Exception {
        Configuration config = HBaseConfiguration.create();
        HTable table = new HTable(config, "Requests");
        Vertx vertx = VertxFactory.newVertx();
        vertx.createHttpServer().requestHandler((HttpServerRequest request) -> {
            System.out.println("A request has arrived on the server!");
            System.out.println(request.uri());
            MultiMap params = request.params();
            params.entries().stream().forEach((entry) -> {
                try {
                    System.out.println(entry.getKey() + "       " + entry.getValue());
                    Put p = new Put(Bytes.toBytes("row" + System.currentTimeMillis()));
                    p.add(Bytes.toBytes("Value"), Bytes.toBytes("col2"), Bytes.toBytes(request.uri()));
                    table.put(p);
                    table.flushCommits();
                } catch (IOException ex) {
                    Logger.getLogger(HelloVertx.class.getName()).log(Level.SEVERE, null, ex);
                }
            });
            request.response().end();
        }).listen(8080, "localhost");
        System.in.read();

    }
}
TOP

Related Classes of hellovertx.HelloVertx

TOP
Copyright © 2018 www.massapi.com. 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.