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


Java Response.suspend方法代码示例

本文整理汇总了Java中org.glassfish.grizzly.http.server.Response.suspend方法的典型用法代码示例。如果您正苦于以下问题:Java Response.suspend方法的具体用法?Java Response.suspend怎么用?Java Response.suspend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.glassfish.grizzly.http.server.Response的用法示例。


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

示例1: GrizzlyServerHttpExchange

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public GrizzlyServerHttpExchange(Request request, Response response) {
  this.request = request;
  this.response = response;
  request.getContext().getConnection().addCloseListener(new CloseListener<Closeable,
    ICloseType>() {
    @Override
    public void onClosed(Closeable closeable, ICloseType type) throws
      IOException {
      closeActions.fire();
    }
  });
  // To detect closed connection
  // From https://github.com/GrizzlyNIO/grizzly-mirror/blob/2_3_17/modules/comet/src/main/java
  // /org/glassfish/grizzly/comet/CometContext.java#L250
  request.getInputBuffer().initiateAsyncronousDataReceiving();
  response.suspend();
}
 
开发者ID:cettia,项目名称:asity,代码行数:19,代码来源:GrizzlyServerHttpExchange.java

示例2: service

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {
	try {
		int port = request.getRemotePort();
		String address = request.getRemoteAddr();
		String holdConn = request.getParameter("hold");

		if ("false".equals(holdConn)) {
			logger.info("recv short request:[{}:{}]", address, port);
			String messageJson = request.getParameter("data");
			IMessage msg = context.getCodec().decode(messageJson);
			context.getMessageCenter().send(msg);
		} else {
			logger.info("recv long-poll request:[{}:{}]", address, port);
			PushError erro = context.beAddSub(request.getParameterMap());
			if (erro != null) {
				writeInfo(response, erro);
				return;
			}
			long timeout = context.getConfig().getConnTimeout();
			IRemoteSubcriber sub = new PollSubcriber(response, context);
			response.suspend(timeout, TimeUnit.MILLISECONDS, handler, this);
			context.getMessageCenter().addSubscriber(sub);
			request.setAttribute("sub", sub);
			
			logger.info("create long-poll client:[{}:{}]", address, port);
		}
	} catch (Exception e) {
		logger.error("occur error when process request", e);
	}
}
 
开发者ID:coderczp,项目名称:HtmlSocket,代码行数:32,代码来源:LongPollServer.java

示例3: GrizzlyServerHttpExchange

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public GrizzlyServerHttpExchange(Request request, Response response) {
    this.request = request;
    this.response = response;
    request.getContext().getConnection().addCloseListener(new CloseListener<Closeable, org.glassfish.grizzly.ICloseType>() {
        @Override
        public void onClosed(Closeable closeable, org.glassfish.grizzly.ICloseType type) throws IOException {
            closeActions.fire();
        }
    });
    // To detect closed connection
    // From https://github.com/GrizzlyNIO/grizzly-mirror/blob/2_3_17/modules/comet/src/main/java/org/glassfish/grizzly/comet/CometContext.java#L250
    request.getInputBuffer().initiateAsyncronousDataReceiving();
    response.suspend();
}
 
开发者ID:vibe-project,项目名称:vibe-java-platform,代码行数:16,代码来源:GrizzlyServerHttpExchange.java

示例4: service

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
public void service(final Request req, final Response resp) throws Exception {
	// suspend the response, allowing for async processing
	resp.suspend();
	LogManager.getLogger(this).info(String.format("Request: %s, IP %s", req.getRequestURI(), req.getRemoteAddr()));
	int length = req.getContentLength();
	if (length > Server.MAX_POST_SIZE || length < Server.MIN_POST_SIZE){
		m_errorHandler.handleInvalidPost(null, resp, new IllegalArgumentException("Invalid content-length of " + length));
		return; // FIXME- this probably wants to be handled using an error-handling mechanism.
	}
	final ByteBuffer postBytes = ByteBuffer.allocate(req.getContentLength());
	final NIOInputStream in = req.getNIOInputStream();

	in.notifyAvailable(new ReadHandler() {
		
		public void onError(Throwable t) {
			try {
				m_errorHandler.handleInvalidPost(postBytes, resp, t);
			} catch (IOException e) {
				e.printStackTrace(); // FIXME
			}
			resp.resume();
		}
		
		public void onDataAvailable() throws Exception {
			addToBuffer(in, postBytes);
			in.notifyAvailable(this);
		}
		
		public void onAllDataRead() throws Exception {
			addToBuffer(in, postBytes);
			postBytes.flip();									
			m_successHandler.handlePost(postBytes, req, resp);
		}
	});
	
}
 
开发者ID:davruet,项目名称:shenanigans.io,代码行数:37,代码来源:AsyncPostHandler.java

示例5: service

import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@Override
@Suspendable
public void service(final Request request, final Response response) throws CharConversionException {
    final ResponseWriter responseWriter = new ResponseWriter(response, configSetStatusOverSendError);
    try {
        logger.debugLog("GrizzlyHttpContainer.service(...) started");

        final URI baseUri = getBaseUri(request);
        final URI requestUri = getRequestUri(request);
        final ContainerRequest requestContext = new ameba.container.server.Request(baseUri,
                requestUri, request.getMethod().getMethodString(),
                getSecurityContext(request), new GrizzlyRequestPropertiesDelegate(request)) {
            @Override
            public String getRemoteAddr() {
                return request.getRemoteAddr();
            }

            @Override
            public String getRemoteHost() {
                return request.getRemoteHost();
            }

            @Override
            public int getRemotePort() {
                return request.getRemotePort();
            }

            @Override
            public String getLocalAddr() {
                return request.getLocalAddr();
            }

            @Override
            public String getLocalName() {
                return request.getLocalName();
            }

            @Override
            public int getLocalPort() {
                return request.getLocalPort();
            }

            @Override
            public URI getRawReqeustUri() {
                return UriBuilder.fromUri(requestUri).build();
            }
        };
        requestContext.setEntityStream(request.getInputStream());
        for (final String headerName : request.getHeaderNames()) {
            requestContext.headers(headerName, request.getHeaders(headerName));
        }
        requestContext.setWriter(responseWriter);

        response.suspend();
        HttpFiber.start(() -> {
            requestContext.setRequestScopedInitializer(injectionManager -> {
                injectionManager.<Ref<Request>>getInstance(RequestType).set(request);
                injectionManager.<Ref<Response>>getInstance(ResponseType).set(response);
            });
            appHandler.handle(requestContext);
        });
    } finally {
        logger.debugLog("GrizzlyHttpContainer.service(...) finished");
    }
}
 
开发者ID:icode,项目名称:ameba-container-grizzly,代码行数:66,代码来源:GrizzlyHttpContainer.java


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