Example usage for javax.servlet ServletContextAttributeEvent getServletContext

List of usage examples for javax.servlet ServletContextAttributeEvent getServletContext

Introduction

In this page you can find the example usage for javax.servlet ServletContextAttributeEvent getServletContext.

Prototype

public ServletContext getServletContext() 

Source Link

Document

Return the ServletContext that changed.

Usage

From source file:org.atmosphere.ttrex.RaceAtmosphereHandler.java

public void attributeAdded(ServletContextAttributeEvent event) {

    readQueue = (BlockingQueue<ArrayList>) event.getServletContext().getAttribute("readQueue");

    //take first element of writeQueue

    if (readQueue == null || queueInit == true) {
        //System.out.println("queue is null");
    } else {//from  w  ww  .  java2s  .  c om
        queueInit = true;

        Thread thread = new Thread(new Runnable() {
            public void run() {
                ArrayList item;
                try {
                    //while (!(item = queue.take()).equals(SHUTDOWN_REQ)) {
                    while (true) {
                        item = readQueue.take();
                        JSONObject obj = new JSONObject();
                        //String s = JSONValue.toJSONString(item);
                        obj.put("type", item.get(0));
                        obj.put("data", item);
                        obj.put("source", "server");
                        MetaBroadcaster.getDefault().broadcastTo("/ttrex", obj.toJSONString());
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();

        ArrayList frame = new ArrayList();
        frame.add("init");
        writeQueue.add(frame);
        writeQueue.add(frame);
        event.getServletContext().setAttribute("writeQueue", writeQueue);
    }

    if (queueWriteInit == true || queueInit == false) {
        //System.out.println("writeQueue is null");
    } else {
        queueWriteInit = true;
    }
}

From source file:org.openanzo.combus.bayeux.BayeuxJMSBridge.java

public void attributeAdded(ServletContextAttributeEvent scab) {
    Properties properties = (Properties) scab.getServletContext().getAttribute("initParams");
    if (scab.getName().equals(Bayeux.ATTRIBUTE)) {
        Bayeux bayeux = (Bayeux) scab.getValue();
        initialize(bayeux, properties);/*from  w  w  w  .  j  a  v  a2s  . c o m*/
    }
}