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


Java ContinuationSupport类代码示例

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


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

示例1: doGet

import org.eclipse.jetty.continuation.ContinuationSupport; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Enumeration<String> acceptValues = request.getHeaders("Accept");
    while (acceptValues.hasMoreElements()) {
        String accept = acceptValues.nextElement();
        if (accept.equals("text/event-stream")) {
            EventSource eventSource = newEventSource(request);
            if (eventSource == null) {
                response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
            } else {
                respond(request, response);
                Continuation continuation = ContinuationSupport.getContinuation(request);
                // Infinite timeout because the continuation is never resumed,
                // but only completed on close
                continuation.setTimeout(0L);
                continuation.suspend(response);
                EventSourceEmitter emitter = new EventSourceEmitter(eventSource, continuation);
                emitter.scheduleHeartBeat();
                open(eventSource, emitter);
            }
            return;
        }
    }
    super.doGet(request, response);
}
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:26,代码来源:EventSourceServlet.java

示例2: enterSleep

import org.eclipse.jetty.continuation.ContinuationSupport; //导入依赖的package包/类
@Override
protected void enterSleep()
{
    continuation = ContinuationSupport.getContinuation(request);
    continuation.setAttribute(ATTRIBUTE_SLEEPER, this);
    continuation.setTimeout(0);
    continuation.suspend();

    synchronized (workLock)
    {
        if (queuedWork) {
            continuation.resume(); // will eventually trigger resumeWork() from a container thread
        } else {
            workInProgress = false; // open up for doing new work
        }
        queuedWork = false;
    }
}
 
开发者ID:directwebremoting,项目名称:dwr,代码行数:19,代码来源:JettyContinuationSleeper.java

示例3: handle

import org.eclipse.jetty.continuation.ContinuationSupport; //导入依赖的package包/类
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
  metrics.getRequestsMeter().mark();

  if (!target.equals(s3Configuration.getLocalDownloadPath())) {
    metrics.getClientErrorsMeter().mark();
    response.sendError(404);
    return;
  }

  if (!request.getMethod().equalsIgnoreCase(HttpMethod.POST.name())) {
    metrics.getClientErrorsMeter().mark();
    response.sendError(405);
    return;
  }

  Optional<ArtifactDownloadRequest> artifactOptional = readDownloadRequest(request);

  if (!artifactOptional.isPresent()) {
    metrics.getClientErrorsMeter().mark();
    response.sendError(400);
    return;
  }

  Continuation continuation = ContinuationSupport.getContinuation(request);
  continuation.suspend(response);

  downloaderCoordinator.register(continuation, artifactOptional.get());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:30,代码来源:SingularityS3DownloaderHandler.java

示例4: doGet

import org.eclipse.jetty.continuation.ContinuationSupport; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
  Continuation continuation = ContinuationSupport.getContinuation(request);
  if (continuation.isExpired()) {
    // timeout - just send a blank response and tell the connection that its continuation has timed out
    String clientId = (String) continuation.getAttribute(CLIENT_ID);
    if (clientId != null) {
      // TODO will this always get the correct continuation?
      _connectionManager.longPollHttpTimeout(clientId, continuation);
    }
    return;
  }
  String results = (String) request.getAttribute(RESULTS);
  // if this is the first time the request has been dispatched the results will be null. if the request has been
  // dispatched before and is being dispatched again after its continuation was resumed the results will be populated
  if (results == null) {
    setUpConnection(continuation, request, response);
  } else {
    // Send the results
    s_logger.debug("Writing results to HTTP response {}", results);
    response.getWriter().write(results);
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:24,代码来源:LongPollingServlet.java

示例5: doGet

import org.eclipse.jetty.continuation.ContinuationSupport; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {

  logger.info("doGet:" + Thread.currentThread().getName());
  final Continuation cnt = ContinuationSupport.getContinuation(req);

  //aka retry
  //cnt.setTimeout(5000);
  cnt.suspend(resp);

  webService.htmlStream().subscribe(new Action1<String>() {
    @Override
    public void call(String response) {
      logger.info("Notify:" + Thread.currentThread().getName());
      respond(response + "\n", cnt);
    }
  }, new Action1<Throwable>() {
    @Override
    public void call(Throwable throwable) {
      respond(throwable.getMessage(), cnt);
    }
  });
}
 
开发者ID:haghard,项目名称:jetty-jersey-guice-rxjava-scala,代码行数:25,代码来源:GeneralServlet.java

示例6: JettyTransportCommand

import org.eclipse.jetty.continuation.ContinuationSupport; //导入依赖的package包/类
public JettyTransportCommand(final HttpServletRequest request, final HttpServletResponse response, IdentityTokenResolver identityTokenResolver) {
	status = new AtomicReference<CommandStatus>(CommandStatus.InProgress);
	this.request = request;
	this.response = response;
          this.identityTokenResolver = identityTokenResolver;

	HeaderUtils.setNoCache(response);
	continuation = ContinuationSupport.getContinuation(request);
	if (continuation.isInitial()) {
		continuation.setTimeout(MILLI * timeoutInSeconds );
		continuation.suspend(response);
		continuation.addContinuationListener(this);
	}

	buildPathInfo(request);
}
 
开发者ID:betfair,项目名称:cougar,代码行数:17,代码来源:JettyHandler.java

示例7: handleAsynchronous

import org.eclipse.jetty.continuation.ContinuationSupport; //导入依赖的package包/类
@Override
public void handleAsynchronous(Request baseRequest,
    HttpServletRequest request, HttpServletResponse response) {
  // Jetty continuations
  // TODO(spenceg) Try Servlet 3.0 if this doesn't work
  Continuation continuation = ContinuationSupport.getContinuation(request);
  continuation.suspend(response); //Start Async Processing

  TranslationRequest translationRequest = (TranslationRequest) baseRequest;
  
  // Translate to uppercase!
  List<String> translation = Arrays.asList(translationRequest.text.toUpperCase().split("\\s+"));
  List<String> alignments = new ArrayList<>(2);
  alignments.add("1-2");
  alignments.add("2-1");
  TranslationQuery query = new TranslationQuery(translation, alignments, 1.0);
  List<TranslationQuery> queryList = new ArrayList<>(1);
  queryList.add(query);
  Type t = new TypeToken<TranslationReply>() {}.getType();
  TranslationReply baseResponse = new TranslationReply(queryList);

  // Simulate a long call to the MT system
  Random random = new Random();
  try {
    Thread.sleep(500 + random.nextInt(1000));
  } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
  
  ServiceResponse serviceResponse = new ServiceResponse(baseResponse, t);
  request.setAttribute(PhrasalServlet.ASYNC_KEY, serviceResponse);   
  continuation.resume(); // Re-dispatch/ resume to generate response
}
 
开发者ID:stanfordnlp,项目名称:phrasal,代码行数:35,代码来源:TranslationRequestHandlerMock.java

示例8: handlePackets

import org.eclipse.jetty.continuation.ContinuationSupport; //导入依赖的package包/类
private void handlePackets(Request baseRequest, HttpServletRequest request,
		HttpServletResponse response) throws IOException {
	String domain = request.getParameter("domain");
	Ticket ticket = Ticket.parse(request.getParameter("ticket"));
	EndOid useroid = makeoid(domain, ticket);
	String callback = g(request, "callback");

	Subscriber subscriber = router.lookup(useroid, ticket);
	if (subscriber == null) {
		jsonReturn(
				new JSONResult(
						callback
								+ "({\"status\": \"error\", \"message\": \"subscriber not found\"})"),
				response, HttpServletResponse.SC_BAD_REQUEST);
		return;
	}
	synchronized (subscriber) {
		if (subscriber.queue.size() > 0) {
			List<Packet> packets = new ArrayList<Packet>();
			Packet packet = null;
			while ((packet = subscriber.queue.poll()) != null) {
				packets.add(packet);
			}
			JSONResult result = new Encoder(packets).jsonResult();
			// Send one chat message
			response.setContentType("application/javascript;charset=utf-8");
			response.setStatus(HttpServletResponse.SC_OK);
			response.getOutputStream().write((callback + "(").getBytes());
			response.getOutputStream().write(result.toJSON());
			response.getOutputStream().write(new byte[] { ')' });
			response.getOutputStream().flush();
		} else {
			Continuation continuation = ContinuationSupport
					.getContinuation(request);
			if (continuation.isInitial()) {
				// No chat in queue, so suspend and wait for timeout or chat
				continuation.setTimeout(20000);
				continuation.suspend();
				subscriber.continuation = continuation;
			} else {
				// Timeout so send empty response
				response.setContentType("application/javascript;charset=utf-8");
				response.setStatus(HttpServletResponse.SC_OK);
				response.getWriter().print(
						callback + "({\"status\": \"ok\"})");
				response.getWriter().flush();
			}
		}
		subscriber.lastActive = System.currentTimeMillis();

	}
}
 
开发者ID:nextalk,项目名称:webim-server-java,代码行数:53,代码来源:HttpHandler.java

示例9: handle

import org.eclipse.jetty.continuation.ContinuationSupport; //导入依赖的package包/类
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
  metrics.getRequestsMeter().mark();

  if (!target.equals(s3Configuration.getLocalDownloadPath())) {
    metrics.getClientErrorsMeter().mark();
    response.sendError(404);
    return;
  }

  if (!request.getMethod().equalsIgnoreCase(HttpMethod.POST.name())) {
    metrics.getClientErrorsMeter().mark();
    response.sendError(405);
    return;
  }

  Optional<ArtifactDownloadRequest> artifactOptional = readDownloadRequest(request);

  if (!artifactOptional.isPresent()) {
    metrics.getClientErrorsMeter().mark();
    response.sendError(400);
    return;
  }

  Continuation continuation = ContinuationSupport.getContinuation(request);
  continuation.suspend(response);
  if (artifactOptional.get().getTimeoutMillis().isPresent()) {
    continuation.setTimeout(artifactOptional.get().getTimeoutMillis().get());
  }

  downloaderCoordinator.register(continuation, artifactOptional.get());
}
 
开发者ID:HubSpot,项目名称:Singularity,代码行数:33,代码来源:SingularityS3DownloaderHandler.java

示例10: ContinuationJetty

import org.eclipse.jetty.continuation.ContinuationSupport; //导入依赖的package包/类
public ContinuationJetty(HttpServletRequest req)
{
  mContinuation = ContinuationSupport.getContinuation(req);
}
 
开发者ID:ZeXtras,项目名称:OpenZAL,代码行数:5,代码来源:ContinuationJetty.java

示例11: process

import org.eclipse.jetty.continuation.ContinuationSupport; //导入依赖的package包/类
public void process(HttpServletRequest request,
	HttpServletResponse response, int method, Player player) {
  	if (method != Action.METHOD_POST) {
  		write(request, response, ActionForward.error("Use POST only."));
  		return;
  	}
  	
  	if (player == null) {
  		write(request, response, ActionForward.disconnected());
  		return;
  	}
  	
// Vérifie que sa clé de sécurité est valide
if (request.getParameter(SECURITY_KEY) == null ||
		!player.getSecurityKey().equals(request.getParameter(SECURITY_KEY))) {
	write(request, response, ActionForward.error("Invalid security key."));
	return;
}

List<Update> updates =
	UpdateManager.getInstance().getUpdatesByPlayer(player.getId());

if (updates.size() == 0) {
	Continuation continuation = ContinuationSupport.getContinuation(request);
	
	if (continuation.isInitial()) {
		continuation.setTimeout(player.isSettingsOptimizeConnection() ?
			CONTINUATION_TIMEOUT_PROXY : CONTINUATION_TIMEOUT_DEFAULT);
		continuation.suspend();
		player.setContinuation(continuation);
		return;
	}
}

player.setContinuation(null);

try {
	String json = UpdateTools.formatUpdates(player, updates);
	updates.clear();
	
	write(request, response, ActionForward.success(json));
} catch (Exception e) {
	e.printStackTrace();
}
  }
 
开发者ID:Orichievac,项目名称:FallenGalaxy,代码行数:46,代码来源:PollingServlet.java


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