本文整理汇总了Java中org.atmosphere.config.service.ManagedService类的典型用法代码示例。如果您正苦于以下问题:Java ManagedService类的具体用法?Java ManagedService怎么用?Java ManagedService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ManagedService类属于org.atmosphere.config.service包,在下文中一共展示了ManagedService类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generate
import org.atmosphere.config.service.ManagedService; //导入依赖的package包/类
@Override
public JavaScriptResult generate(Class<?> javaClass) throws SingleFileGeneratorException {
String messageQueueUrl = javaClass.getAnnotation(ManagedService.class).path();
StjsJavaScriptClassBuilder builder = new StjsJavaScriptClassBuilder(javaClass)
.constructor(javaClass)
._constructor()
.function(javaClass, "subscribe", "callbacks")
.code("var request = {};").newLine()
.code("$.extend(request, callbacks);").newLine()
.newLine()
.code("request.url =").literal(messageQueueUrl).semicolon().newLine()
.code("request.contentType = ").literal("application/json").semicolon().newLine()
.code("request.trackMessageLength = ").literal(true).semicolon().newLine()
.code("request.shared = ").literal(false).semicolon().newLine()
.code("request.transport = ").literal("websocket").semicolon().newLine()
.code("request.fallbackTransport = ").literal("long-polling").semicolon().newLine()
.newLine()
.if$("callbacks.onMessage")
.code("request.onMessage = ").anonymousFunction("response")
.code("response.data = JSON.parse(response.responseBody, %s);",
JsonHelper.PARSE_REVIVER_FUNCTION).newLine()
.code("delete response.responseBody;").newLine()
.code("callbacks.onMessage(response);").newLine()
._function()
._if()
.newLine()
.code("var connection = $.atmosphere.subscribe(request);").newLine()
.code("var oldPushFunction = connection.push;").newLine()
.code("connection.push = ").anonymousFunction("data")
.code("oldPushFunction.call(connection, JSON.stringify(data, %s));",
JsonHelper.STRINGIFY_REPLACER_FUNCTION).newLine()
._function()
.newLine()
.code("return connection;").newLine()
._function();
return new JavaScriptResult(builder.create());
}