Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) SiteWhere, LLC. All rights reserved. http://www.sitewhere.com
   *
   * The software in this package is published under the terms of the CPAL v1.0
   * license, a copy of which has been included with this distribution in the
   * LICENSE.txt file.
   */
  package com.sitewhere.device.communication.websocket;
  
 import java.net.URI;
 import java.util.List;
 import java.util.Map;
 
 
 
Event receiver that pulls data from a web socket.

Parameters:
<T>
Author(s):
Derek
 
 public abstract class WebSocketEventReceiver<T> extends LifecycleComponent implements
Static logger
 
 	private static Logger LOGGER = Logger.getLogger(WebSocketEventReceiver.class);

User property that references the event reciever
 
 	public static final String PROP_EVENT_RECEIVER = "sw.event.receiver";

Parent event source
 
Web socket session
 
 	private Session session;

Web socket URL to connect to
 
 	private String webSocketUrl;

Headers passed in web socket configuration
 
 	private Map<StringStringheaders = new HashMap<StringString>();
 
 	public WebSocketEventReceiver() {
 	}

Get concrete WebSocketClient implementation class.

Returns:
 
 	public abstract Class<? extends EndpointgetWebSocketClientClass();
 
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see com.sitewhere.spi.server.lifecycle.ILifecycleComponent#start()
 	 */
 	public void start() throws SiteWhereException {
 		WebSocketContainer container = ContainerProvider.getWebSocketContainer();
 				ClientEndpointConfig.Builder.create().configurator(new WebSocketConfigurator()).build();
 		try {
 			 =
 		} catch (DeploymentException e) {
 			throw new SiteWhereException("Unable to connect to web socket."e);
 		} catch (IOException e) {
 			throw new SiteWhereException("Unable to connect to web socket."e);
 		}
 	}
 
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see com.sitewhere.spi.server.lifecycle.ILifecycleComponent#stop()
 	 */
 	public void stop() throws SiteWhereException {
		try {
catch (IOException e) {
			.error("IOException closing web socket: "e);
		}
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.sitewhere.spi.server.lifecycle.ILifecycleComponent#getLogger()
	 */
	public Logger getLogger() {
		return ;
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.sitewhere.spi.device.communication.IInboundEventReceiver#getDisplayName()
	 */
	public String getDisplayName() {
		return "WebSocket()";
	}
	public void onEventPayloadReceived(T payload) {
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.sitewhere.spi.device.communication.IInboundEventReceiver#setEventSource(com
	 * .sitewhere.spi.device.communication.IInboundEventSource)
	 */
	public void setEventSource(IInboundEventSource<T> source) {
		this. = source;
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.sitewhere.spi.device.communication.IInboundEventReceiver#getEventSource()
	 */
		return ;
	}

Configurator that passes in configured headers.

Author(s):
Derek
		public void beforeRequest(Map<StringList<String>> headers) {
			for (String key : extHeaders.keySet()) {
				headers.put(key, Arrays.asList(extHeaders.get(key)));
			}
			super.beforeRequest(headers);
		}
	}
	public String getWebSocketUrl() {
		return ;
	}
	public void setWebSocketUrl(String webSocketUrl) {
		this. = webSocketUrl;
	}
	public Map<StringStringgetHeaders() {
		return ;
	}
	public void setHeaders(Map<StringStringheaders) {
		this. = headers;
	}
New to GrepCode? Check out our FAQ X