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


Java ChannelService类代码示例

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


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

示例1: doPost

import com.google.appengine.api.channel.ChannelService; //导入依赖的package包/类
/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
	// In the handler for _ah/channel/connected/
	ChannelService channelService = ChannelServiceFactory.getChannelService();
	ChannelPresence presence = channelService.parsePresence(request);
	
	String clientId = presence.clientId();
	boolean connected = presence.isConnected();
	
	log.info("Client = " + clientId + ", connected = " + connected);
	
	if(!connected) {
		// remove them from the datastore
	    Client.remove(clientId);
	}
}
 
开发者ID:omerio,项目名称:raspberrypi-appengine-portal,代码行数:20,代码来源:ChannelHandler.java

示例2: getToken

import com.google.appengine.api.channel.ChannelService; //导入依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/token")
public String getToken(@HeaderParam("Authorization") String token)  {
	try {
	if (!validCredentials(token))
		return null;
	UsersDelegator qu = new UsersDelegator(token);
	String myAccount = qu.getCurrentUserAccount();
	
	ChannelService channelService = ChannelServiceFactory.getChannelService();
	return "{ \"token\": \""+channelService.createChannel(myAccount)+"\"}";

	} catch (Exception e) {
		e.printStackTrace();
		return e.getMessage();
	}
}
 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:19,代码来源:ChannelAPI.java

示例3: getToken3m

import com.google.appengine.api.channel.ChannelService; //导入依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/token3m")
public String getToken3m(@HeaderParam("Authorization") String token)  {
	try {
	if (!validCredentials(token))
		return null;
	UsersDelegator qu = new UsersDelegator(token);
	String myAccount = qu.getCurrentUserAccount();
	
	ChannelService channelService = ChannelServiceFactory.getChannelService();
	return "{ \"token\": \""+channelService.createChannel(myAccount,2)+"\"}";

	} catch (Exception e) {
		e.printStackTrace();
		return e.getMessage();
	}
}
 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:19,代码来源:ChannelAPI.java

示例4: IndexServlet

import com.google.appengine.api.channel.ChannelService; //导入依赖的package包/类
/**
 * Constructor.
 *
 * @param channelService service for handling channel communication
 * @param networks used to get a list of networks
 * @param userService the App Engine service for user management
 * @param memcacheService the App Engine caching service
 * @param expirationDelta the cache expiration delta in seconds
 * @param authorizationCodeFlowFactory used to get an OAuth2 flow
 * @param redirectUrl where to direct the user once authorization is done
 */
@Inject
public IndexServlet(ChannelService channelService,
    Networks networks,
    UserService userService,
    MemcacheService memcacheService,
    @Named("expirationDelta") int expirationDelta,
    AuthorizationCodeFlowFactory authorizationCodeFlowFactory,
    @Named("redirectUrl") String redirectUrl) {
  super(authorizationCodeFlowFactory, redirectUrl);
  this.channelService = channelService;
  this.networks = networks;
  this.memcacheService = memcacheService;
  this.userService = userService;
  this.expirationDelta = expirationDelta;
}
 
开发者ID:googleads,项目名称:googleads-dfp-java-dfp-playground,代码行数:27,代码来源:IndexServlet.java

示例5: create

import com.google.appengine.api.channel.ChannelService; //导入依赖的package包/类
@ApiMethod(name = "data.create", httpMethod = "post")
public SensorData create(SensorData data, User user) {
	
    // check the user is authenticated and authorised
	if(user == null) {
		log.warning("User is not authenticated");
		throw new RuntimeException("Authentication required!");
		
	} else if(!Constants.EMAIL_ADDRESS.equals(user.getEmail())) {
		
		log.warning("User is not authorised, email: " + user.getEmail());
		throw new RuntimeException("Not authorised!");
	}
	
	data.save();
	
	try {
	    // notify the client channels
	    ChannelService channelService = ChannelServiceFactory.getChannelService();

	    List<Client> clients = Client.findAll();
	    String json = GSON.toJson(data);

	    for(Client client: clients) {
	        channelService.sendMessage(new ChannelMessage(client.getId(), json));
	    }
	    
	} catch(Exception e) {
	    log.log(Level.SEVERE, "Failed to notify connected clients", e);
	}
		
	return data;
}
 
开发者ID:omerio,项目名称:raspberrypi-appengine-portal,代码行数:34,代码来源:SensorDataEndpoint.java

示例6: SlobMessageRouter

import com.google.appengine.api.channel.ChannelService; //导入依赖的package包/类
@Inject
public SlobMessageRouter(MemcacheTable.Factory memcacheFactory, ChannelService channelService,
    @SlobChannelExpirationSeconds int expirationSeconds) {
  this.objectListeners = memcacheFactory.create(LISTENER_MEMCACHE_TAG);
  this.clientTokens = memcacheFactory.create(CLIENTS_MEMCACHE_TAG);
  this.channelService = channelService;
  this.expirationSeconds = expirationSeconds;
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:9,代码来源:SlobMessageRouter.java

示例7: getShortToken

import com.google.appengine.api.channel.ChannelService; //导入依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/token2m")
public String getShortToken(@HeaderParam("Authorization") String token)  {
	if (!validCredentials(token))
		return null;
	UsersDelegator qu = new UsersDelegator(token);
	String myAccount = qu.getCurrentUserAccount();
	
	ChannelService channelService = ChannelServiceFactory.getChannelService();
	return "clientId: "+myAccount+" token2m " + channelService.createChannel(myAccount, 2);

}
 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:14,代码来源:ChannelAPI.java

示例8: getRun

import com.google.appengine.api.channel.ChannelService; //导入依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/run/{account}")
public String getRun(@PathParam("account") String account)  {		
	ChannelService channelService = ChannelServiceFactory.getChannelService();
	Run r = new Run();
	r.setGameId(123l);
	r.setTitle("een game");
	channelService.sendMessage(new ChannelMessage(account, toJson(r)));
	return "sent";
}
 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:12,代码来源:ChannelAPI.java

示例9: sendUpdateToUser

import com.google.appengine.api.channel.ChannelService; //导入依赖的package包/类
public static void sendUpdateToUser(Message  model) {
  if (model.getSendTo() != null && model.getSendTo()!="") {
    
     PubsubJSONSerializer<Message> serialize = new PubsubJSONSerializer<Message>();
     String messagePayload = serialize.POJOSerializer(model);
     ChannelService channelService = ChannelServiceFactory.getChannelService();
     String channelKey = LiveFeedChannel.getChannelKey(model.getSendTo());
     channelService.sendMessage(new ChannelMessage(channelKey, messagePayload));
    
  }
}
 
开发者ID:satypro,项目名称:GAELivePubSub,代码行数:12,代码来源:LiveFeedChannel.java

示例10: pushUpdates

import com.google.appengine.api.channel.ChannelService; //导入依赖的package包/类
public static void pushUpdates(List<User> users, String message, String url) {
	ChannelService channelService = ChannelServiceFactory
			.getChannelService();
	try {
		JSONObject json = new JSONObject();
		json.put("message", message);
		json.put("link", url);
		for (User user : users) {
			channelService.sendMessage(new ChannelMessage(KeyFactory
					.keyToString(user.getKey()), json.toString()));
		}
	} catch (JSONException e) {
		e.printStackTrace();
	}
}
 
开发者ID:hasier,项目名称:voxpopuli,代码行数:16,代码来源:Utils.java

示例11: SlobMessageRouter

import com.google.appengine.api.channel.ChannelService; //导入依赖的package包/类
@Inject
public SlobMessageRouter(MemcacheTable.Factory memcacheFactory, ChannelService channelService,
    Provider<PresenceEndpoint> presence) {
  this.clientTokens = memcacheFactory.create(CLIENTS_MEMCACHE_TAG);
  this.channelService = channelService;
  this.presence = presence;
}
 
开发者ID:larrytin,项目名称:realtime-server-appengine,代码行数:8,代码来源:SlobMessageRouter.java

示例12: doGet

import com.google.appengine.api.channel.ChannelService; //导入依赖的package包/类
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
	ChannelService channelService = ChannelServiceFactory.getChannelService();
	
	//The token must be based on some unique identifier for the client - I am using the current time
	//for demo purposes...
	String clientId = String.valueOf(System.currentTimeMillis());
    String token = channelService.createChannel(clientId);
    
    //Subscribe this client
    MultichannelChatManager.addSub(clientId);
    
    //Reply with the token
	res.setContentType("text/plain");
	res.getWriter().print(token);
}
 
开发者ID:kwhinnery,项目名称:gae-chat,代码行数:16,代码来源:ChatServlet.java

示例13: sendMessage

import com.google.appengine.api.channel.ChannelService; //导入依赖的package包/类
public static void sendMessage(String body, String source) {
	Iterator<String> it = subs.iterator();
	while (it.hasNext()) {
		String sub = it.next();
		String messageBody = source + ": " + body;

		// We assume an at symbol is an XMPP client...
		if (sub.indexOf("@") >= 0) {
			JID jid = new JID(sub);
			Message msg = new MessageBuilder().withRecipientJids(jid).withBody(messageBody).build();
			XMPPService xmpp = XMPPServiceFactory.getXMPPService();
			xmpp.sendMessage(msg);
		}
		
		// If it starts with a "+" it's an SMS number...
		else if (sub.startsWith("+")) {
			TwilioRestClient client = new TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN");

			Map<String, String> params = new HashMap<String, String>();
			params.put("Body", messageBody);
			params.put("To", sub);
			params.put("From", "+16122948105");

			SmsFactory messageFactory = client.getAccount().getSmsFactory();

			try {
				Sms message = messageFactory.create(params);
				System.out.println(message.getSid());
			} catch (TwilioRestException e) {
				e.printStackTrace();
			}
		}

		// Otherwise, it's a browser-based client
		else {
			ChannelService channelService = ChannelServiceFactory.getChannelService();
			channelService.sendMessage(new ChannelMessage(sub,messageBody));
		}
	}
}
 
开发者ID:kwhinnery,项目名称:gae-chat,代码行数:41,代码来源:MultichannelChatManager.java

示例14: doPost

import com.google.appengine.api.channel.ChannelService; //导入依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String requestURI = req.getRequestURI();
	if (" /_ah/channel/disconnected/".equals(requestURI)) {
		ChannelService channelService = ChannelServiceFactory.getChannelService();
		ChannelPresence presence = channelService.parsePresence(req);
		String clientId = presence.clientId();
		log.info("disconnected " + clientId);
	}
}
 
开发者ID:rzymek,项目名称:obsolete-web-boards-gwt,代码行数:11,代码来源:ManagerServlet.java

示例15: doGet

import com.google.appengine.api.channel.ChannelService; //导入依赖的package包/类
/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    // get the session 
    HttpSession session = request.getSession();
    String clientId = session.getId();

    log.info("Sending data to client " + clientId);

    Client client = Client.findById(clientId);

    String token = null;

    if(client == null) {

        ChannelService channelService = ChannelServiceFactory.getChannelService();
        log.info("Creating channel for clientId " + clientId);
        // open the channel
        token = channelService.createChannel(clientId);

        client = new Client(clientId, token);
        client.save();
    }
    
 // use the session id and the channel id for this client
    Map<String, Object> data = new HashMap<>();
    token = client.getToken();
    data.put("token", token);

    //createTestData();
    int minutes = 1;
    String timeRange = request.getParameter("timeRange");

    try {
        minutes = Integer.parseInt(timeRange);
        
    } catch(NumberFormatException e) {
        log.warning("Failed to parse number " + timeRange);
    }

    Calendar calendar = new GregorianCalendar();
    calendar.add(Calendar.MINUTE, -minutes);
    Date date = calendar.getTime();
    
    List<SensorData> sensorDataList = SensorData.findByDateTime(date);

    data.put("data", sensorDataList);

    response.setContentType(CONTENT_TYPE_JSON);
    response.getWriter().print(GSON.toJson(data));

}
 
开发者ID:omerio,项目名称:raspberrypi-appengine-portal,代码行数:55,代码来源:StartServlet.java


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