本文整理汇总了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);
}
示例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();
}
};
}
示例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);
}
示例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;
}