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


Java Context.getCurrent方法代码示例

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


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

示例1: ClientResource

import org.restlet.Context; //导入方法依赖的package包/类
/**
 * Constructor.
 * 
 * @param context
 *            The current context.
 * @param request
 *            The handled request.
 * @param response
 *            The handled response.
 */
public ClientResource(Context context, Request request, Response response) {
    if (context == null) {
        context = Context.getCurrent();
    }

    // Don't remove this line.
    // See other constructor ClientResource(Context, Method, Reference)
    response.setRequest(request);

    this.maxRedirects = 10;
    this.retryOnError = true;
    this.retryDelay = 2000L;
    this.retryAttempts = 2;
    this.followingRedirects = true;
    this.requestEntityBuffering = false;
    this.responseEntityBuffering = false;
    init(context, request, response);
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:29,代码来源:ClientResource.java

示例2: newContextProvider

import org.restlet.Context; //导入方法依赖的package包/类
/**
 * Creates a {@link Provider} for the current {@link Context}. Override
 * to use a custom Context provider.
 * 
 * @return A {@link Provider} for the current {@link Context}.
 */
protected Provider<Context> newContextProvider() {
    return new Provider<Context>() {
        public Context get() {
            return Context.getCurrent();
        }
    };
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:14,代码来源:RestletGuice.java

示例3: createThreadWithLocalVariables

import org.restlet.Context; //导入方法依赖的package包/类
/**
 * Creates a new standalone thread with local Restlet thread variable
 * properly set.
 *
 * @param runnable The runnable task to execute.
 * @param name     The thread name.
 * @return The thread with proper variables ready to run the given runnable
 * task.
 */
public static Thread createThreadWithLocalVariables(
        final Runnable runnable, String name) {
    // Save the thread local variables
    final org.restlet.Application currentApplication = org.restlet.Application
            .getCurrent();
    final Context currentContext = Context.getCurrent();
    final Integer currentVirtualHost = org.restlet.routing.VirtualHost
            .getCurrent();
    final Response currentResponse = Response.getCurrent();

    Runnable r = () -> {
        // Copy the thread local variables
        Response.setCurrent(currentResponse);
        Context.setCurrent(currentContext);
        org.restlet.routing.VirtualHost.setCurrent(currentVirtualHost);
        org.restlet.Application.setCurrent(currentApplication);

        try {
            // Run the user task
            runnable.run();
        } finally {
            Engine.clearThreadLocalVariables();
        }
    };

    return new Thread(r, name);
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:37,代码来源:Engine.java

示例4: getUserAgentTemplates

import org.restlet.Context; //导入方法依赖的package包/类
/**
 * Returns the list of user-agent templates defined in "agent.properties"
 * file.
 * 
 * @return The list of user-agent templates defined in "agent.properties"
 *         file.
 * @see The {@link ClientInfo#getAgentAttributes()} method.
 */
private static List<String> getUserAgentTemplates() {
    // Lazy initialization with double-check.
    List<String> u = ClientInfo.userAgentTemplates;
    if (u == null) {
        synchronized (ClientInfo.class) {
            u = ClientInfo.userAgentTemplates;
            if (u == null) {
                // Load from the "agent.properties" file
                java.net.URL userAgentPropertiesUrl = Engine
                        .getResource("org/restlet/data/agent.properties");
                if (userAgentPropertiesUrl != null) {
                    BufferedReader reader;
                    try {
                        reader = new BufferedReader(new InputStreamReader(
                                userAgentPropertiesUrl.openStream(),
                                CharacterSet.UTF_8.getName()),
                                IoUtils.BUFFER_SIZE);
                        String line = reader.readLine();
                        for (; line != null; line = reader.readLine()) {
                            if ((line.trim().length() > 0)
                                    && !line.trim().startsWith("#")) {
                                if (u == null) {
                                    u = new CopyOnWriteArrayList<String>();
                                }
                                u.add(line);
                            }
                        }
                        reader.close();
                    } catch (IOException e) {
                        if (Context.getCurrent() != null) {
                            Context.getCurrent()
                                    .getLogger()
                                    .warn(
                                            "Cannot read '"
                                                    + userAgentPropertiesUrl
                                                            .toString()
                                                    + "' due to: "
                                                    + e.getMessage());
                        }
                    }
                }
                ClientInfo.userAgentTemplates = u;
            }
        }
    }
    return u;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:56,代码来源:ClientInfo.java


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