当前位置: 首页>>代码示例>>Java>>正文


Java AtmosphereResource类代码示例

本文整理汇总了Java中org.atmosphere.cpr.AtmosphereResource的典型用法代码示例。如果您正苦于以下问题:Java AtmosphereResource类的具体用法?Java AtmosphereResource怎么用?Java AtmosphereResource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AtmosphereResource类属于org.atmosphere.cpr包,在下文中一共展示了AtmosphereResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: inspect

import org.atmosphere.cpr.AtmosphereResource; //导入依赖的package包/类
/**
 * @see org.atmosphere.cpr.AtmosphereInterceptor#inspect(org.atmosphere.cpr.AtmosphereResource)
 */
@Override
public Action inspect(final AtmosphereResource atmosphereResource) {
	try {
		SecurityContext context = (SecurityContext) atmosphereResource.getRequest().getSession().getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
		final Authentication auth = context.getAuthentication();
		if (auth instanceof Authentication) {
			MDC.put(UserMdcServletFilter.USER_KEY, auth.getName());
			logger.trace("Username set in MDC");
		}	
	} catch (final NullPointerException e) {}
	return Action.CONTINUE;
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:16,代码来源:RecoverSecurityContextAtmosphereInterceptor.java

示例2: onDisconnect

import org.atmosphere.cpr.AtmosphereResource; //导入依赖的package包/类
public void onDisconnect(AtmosphereResource r, SocketIOSessionOutbound outbound, DisconnectReason reason) {
    log.debug("ondisconnect, reason is :" + reason);

    String sessionId = outbound.getSessionId();

    Collection<String> termIds = sessions.get(sessionId);

    for (String termId : termIds) {
        String key = makeConnectorKey(sessionId, termId);

        TerminalEmulator emulator = connectors.get(key);
        if (emulator != null) {
            emulator.close();
            connectors.remove(key);
        }
    }

    sessions.removeAll(sessionId);
}
 
开发者ID:Coding,项目名称:WebIDE-Backend,代码行数:20,代码来源:SocketIOHandler.java

示例3: sendNotificationAndDisconnect

import org.atmosphere.cpr.AtmosphereResource; //导入依赖的package包/类
/**
 * Tries to send a critical notification to the client and close the
 * connection. Does nothing if the connection is already closed.
 */
private static void sendNotificationAndDisconnect(
    AtmosphereResource resource, String notificationJson) {
    // TODO Implemented differently from sendRefreshAndDisconnect
    try {
        if (resource instanceof AtmosphereResourceImpl
            && !((AtmosphereResourceImpl) resource).isInScope()) {
            // The resource is no longer valid so we should not write
            // anything to it
            getLogger()
                .fine("sendNotificationAndDisconnect called for resource no longer in scope");
            return;
        }
        resource.getResponse().getWriter().write(notificationJson);
        resource.resume();
    } catch (Exception e) {
        getLogger().log(Level.FINEST,
            "Failed to send critical notification to client", e);
    }
}
 
开发者ID:mcollovati,项目名称:vaadin-vertx-samples,代码行数:24,代码来源:VertxPushHandler.java

示例4: broadcastMessage

import org.atmosphere.cpr.AtmosphereResource; //导入依赖的package包/类
private static void broadcastMessage(String uuid, Object message) {
    if (uuid != null) {
        AtmosphereResource res = null;
        int waitTime = 0;
        while ((res = atmosphereResourceFactory.find(uuid)) == null
                && waitTime < MESSAGE_BROADCAST_TIMEOUT) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
            }
            waitTime += 500;
        }
        if (res == null) {
            LOG.warn("Unable to find atmosphere resource for uuid: {}", uuid);
        } else {
            res.getBroadcaster().broadcast(message, res);
        }
    }
}
 
开发者ID:kaaproject,项目名称:sandbox-frame,代码行数:20,代码来源:SandboxServiceImpl.java

示例5: init

import org.atmosphere.cpr.AtmosphereResource; //导入依赖的package包/类
@Override
public void init(ServletConfig sc) throws ServletException {
  super.init(sc);
  framework().addAtmosphereHandler("/", new AtmosphereHandlerAdapter() {
    @Override
    public void onRequest(AtmosphereResource resource) throws IOException {
      if (isWebSocketResource(resource)) {
        if (resource.getRequest().getMethod().equals("GET")) {
          wsActions.fire(new AtmosphereServerWebSocket(resource));
        }
      } else {
        httpActions.fire(new AtmosphereServerHttpExchange(resource));
      }
    }
  });
}
 
开发者ID:cettia,项目名称:asity,代码行数:17,代码来源:AsityAtmosphereServlet.java

示例6: subscribe

import org.atmosphere.cpr.AtmosphereResource; //导入依赖的package包/类
/**
 * Initialize WebSocket based communication channel between the client and
 * the server.
 */
@GET
@Path("/events")
public String subscribe(@Context HttpServletRequest req, @HeaderParam("sessionid") String sessionId)
        throws NotConnectedRestException {
    checkAccess(sessionId);
    HttpSession session = checkNotNull(req.getSession(),
                                       "HTTP session object is null. HTTP session support is requried for REST Scheduler eventing.");
    AtmosphereResource atmosphereResource = checkNotNull((AtmosphereResource) req.getAttribute(AtmosphereResource.class.getName()),
                                                         "No AtmosphereResource is attached with current request.");
    // use session id as the 'topic' (or 'id') of the broadcaster
    session.setAttribute(ATM_BROADCASTER_ID, sessionId);
    session.setAttribute(ATM_RESOURCE_ID, atmosphereResource.uuid());
    Broadcaster broadcaster = lookupBroadcaster(sessionId, true);
    if (broadcaster != null) {
        atmosphereResource.setBroadcaster(broadcaster).suspend();
    }
    return null;
}
 
开发者ID:ow2-proactive,项目名称:scheduling,代码行数:23,代码来源:SchedulerStateRest.java

示例7: getLogin

import org.atmosphere.cpr.AtmosphereResource; //导入依赖的package包/类
@GET 
 @Produces( { MediaType.WILDCARD })
 public Response getLogin(
 		@Context HttpHeaders headers,
 		@QueryParam("u") String user,
 		@QueryParam("p") String password,
 		@QueryParam("d") String device,
 		@QueryParam("jsoncallback") @DefaultValue("callback") String callback,
 		@Context AtmosphereResource resource) {
 	String responseType = MediaTypeHelper.getResponseMediaType(headers.getAcceptableMediaTypes());
 	if(responseType!=null) {
  	return Response.ok(getLoginBean(resource), responseType).build();
 	} else {
return Response.notAcceptable(null).build();
 	}
 }
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:17,代码来源:LoginResource.java

示例8: filter

import org.atmosphere.cpr.AtmosphereResource; //导入依赖的package包/类
@Override
public BroadcastAction filter(String broadcasterId, AtmosphereResource resource,
		Object originalMessage, Object message) {
	final HttpServletRequest request = resource.getRequest();
	try {
		// websocket and HTTP streaming
		if (ResponseTypeHelper.isStreamingTransport(request)
				&& originalMessage instanceof Item) {
			if (message instanceof ItemStateListBean) {
				return new BroadcastAction(ACTION.CONTINUE,
						getSingleResponseObject(
								(ItemStateListBean) message,
								(Item) originalMessage, request));
			} else {
				return new BroadcastAction(ACTION.CONTINUE,
						getSingleResponseObject(null,
								(Item) originalMessage, request));
			}
		}
	} catch (Exception e) {
		logger.error(e.getMessage());
		return new BroadcastAction(ACTION.ABORT, message);
	}
	// pass message to next filter
	return new BroadcastAction(ACTION.CONTINUE, message);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:27,代码来源:ResponseObjectFilter.java

示例9: getPlainItemState

import org.atmosphere.cpr.AtmosphereResource; //导入依赖的package包/类
@GET @Path("/{itemname: [a-zA-Z_0-9]*}/state") 
@Produces( { MediaType.TEXT_PLAIN })
   public SuspendResponse<String> getPlainItemState(
   		@PathParam("itemname") String itemname, 
   		@Context AtmosphereResource resource) {
   	if(TRANSPORT.UNDEFINED.equals(resource.transport())) {
    	Item item = getItem(itemname);
    	if(item!=null) {
			if (logger.isDebugEnabled()) logger.debug("Received HTTP GET request at '{}'.", uriInfo.getPath());
			throw new WebApplicationException(Response.ok(item.getState().toString()).build());
    	} else {
    		if (logger.isDebugEnabled()) logger.info("Received HTTP GET request at '{}' for the unknown item '{}'.", uriInfo.getPath(), itemname);
    		throw new WebApplicationException(404);
    	}
	}
   	
   	BroadcasterFactory broadcasterFactory = resource.getAtmosphereConfig().getBroadcasterFactory();
   	GeneralBroadcaster itemBroadcaster = (GeneralBroadcaster) broadcasterFactory.lookup(GeneralBroadcaster.class, resource.getRequest().getPathInfo(), true); 
	itemBroadcaster.addStateChangeListener(new ItemStateChangeListener());
	return new SuspendResponse.SuspendResponseBuilder<String>()
			.scope(SCOPE.REQUEST)
			.resumeOnBroadcast(!ResponseTypeHelper.isStreamingTransport(resource.getRequest()))
			.broadcaster(itemBroadcaster)
			.outputComments(true).build();
   }
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:26,代码来源:ItemResource.java

示例10: filter

import org.atmosphere.cpr.AtmosphereResource; //导入依赖的package包/类
@Override
public BroadcastAction filter(String broadcasterId, AtmosphereResource resource, Object originalMessage, Object message) {
	final  HttpServletRequest request = resource.getRequest();
	
	try {	
		if(!isDoubleBroadcast(request,message ) ){
			return new BroadcastAction(ACTION.CONTINUE,  message);
		}
		else {
			return new BroadcastAction(ACTION.ABORT,  message);
		}
		
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		return new BroadcastAction(ACTION.ABORT,  message);
	} 
	
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:19,代码来源:DuplicateBroadcastProtectionFilter.java

示例11: handleServiceApi

import org.atmosphere.cpr.AtmosphereResource; //导入依赖的package包/类
/**
 * This is a middle level method to handle the details of Atmosphere and
 * http/ws level of processing request. It will eventually call
 * ApiFactory.process which handles the "pure" Jvm Java only processing
 * 
 * @param r
 *          r
 * @throws Exception
 *           e
 * 
 */
public void handleServiceApi(AtmosphereResource r) throws Exception {
  AtmosphereRequest request = r.getRequest();
  AtmosphereResponse response = r.getResponse();
  OutputStream out = response.getOutputStream();
  response.addHeader("Content-Type", CodecUtils.MIME_TYPE_JSON);
  
  String hack = null;
  byte[] data = null;
  if (request.body() != null) {
    hack = request.body().asString();
    // data = request.body().asBytes();
    if (hack != null){ // FIXME - hack because request.body().asBytes() ALWAYS returns null !!
      data = hack.getBytes();
    }
  }
  api.process(out, r.getRequest().getRequestURI(), data);
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:29,代码来源:WebGui.java

示例12: init

import org.atmosphere.cpr.AtmosphereResource; //导入依赖的package包/类
@Override
public void init(ServletConfig sc) throws ServletException {
    super.init(sc);
    framework().addAtmosphereHandler("/", new AtmosphereHandlerAdapter() {
        @Override
        public void onRequest(AtmosphereResource resource) throws IOException {
            if (isWebSocketResource(resource)) {
                if (resource.getRequest().getMethod().equals("GET")) {
                    wsActions.fire(new AtmosphereServerWebSocket(resource));
                }
            } else {
                httpActions.fire(new AtmosphereServerHttpExchange(resource));
            }
        }
    });
}
 
开发者ID:vibe-project,项目名称:vibe-java-platform,代码行数:17,代码来源:VibeAtmosphereServlet.java

示例13: inspect

import org.atmosphere.cpr.AtmosphereResource; //导入依赖的package包/类
@Override
public Action inspect(AtmosphereResource r)
{
	// do pre-request stuff
	// In certain circumstances push can be called after the standard filter
	// which means there will already
	// be an EM on the thread hence we check if one already exits
	if (EntityManagerProvider.getEntityManager() == null)
	{
		em = EntityManagerProvider.createEntityManager();
		t = new Transaction(em);

		// Create and set the entity manager
		EntityManagerProvider.setCurrentEntityManager(em);
	}

	return super.inspect(r);
}
 
开发者ID:bsutton,项目名称:scoutmaster,代码行数:19,代码来源:AtmosphereFilter.java

示例14: onTextMessage

import org.atmosphere.cpr.AtmosphereResource; //导入依赖的package包/类
@Override
public void onTextMessage(WebSocket webSocket, String data)
		throws IOException {
	AtmosphereResource r = webSocket.resource();
	AtmosphereRequest req = r.getRequest();
	String sessionId = req.getSession(true).getId();
	LOGGER.info("sessionId: {}, resourceId: {} : text message", sessionId,
			r.uuid());

	String json = data.trim();

	Player player = this.sessions.get(sessionId);
	LOGGER.info(player.toString());
	BaseClientGameCommand clientEvent = mapper.readValue(json,
			BaseClientGameCommand.class);
	clientEvent.setPlayer(player);
	clientEvent.setGameId(DEFAULT_GAME_ID);
	this.updater.issueCommand(DEFAULT_GAME_ID, clientEvent);

}
 
开发者ID:LetsCoders,项目名称:MassiveTanks,代码行数:21,代码来源:TankWebSocketHandler.java

示例15: playerExit

import org.atmosphere.cpr.AtmosphereResource; //导入依赖的package包/类
private void playerExit(AtmosphereResource resource) {
	String sessionId = resource.getRequest().getSession(true).getId();
	LOGGER.info("sessionId: {}, resourceId: {} : websocket close",
			sessionId, resource.uuid());

	Player player = this.sessions.get(sessionId);

	// without this check one can crash the server using chrome and chromium
	// at the same time
	if (player != null) {

		// remove connection associated data
		this.sessions.remove(sessionId);
		this.connections.remove(player);

		// tell the game to account for the missing player
		PlayerQuitCommand quit = new PlayerQuitCommand();
		quit.setPlayer(player);
		quit.setGameId(DEFAULT_GAME_ID);
		this.updater.issueCommand(DEFAULT_GAME_ID, quit);

	}

}
 
开发者ID:LetsCoders,项目名称:MassiveTanks,代码行数:25,代码来源:TankWebSocketHandler.java


注:本文中的org.atmosphere.cpr.AtmosphereResource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。