本文整理匯總了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;
}