Restlet timeout - java

How does one change the timeout on a Restlet Client get()?
All I've have been able to find is the obsolete SetConnectTimeout(). I tried context.getParameters().add ( "socketTimeout", "1000" ); with no success.

Basically, this is done by configuring the client connector (class org.restlet.Client):
client.context.getParameters().add ( "parameter", "value" );
I see two distinct contexts and thus two ways to get the client connector.
You are running your client calls inside a org.restlet.Component container
In this case, configure the common client connector hosted by the component:
Component c = new Component();
Client client = c.getClients().add(Protocol.HTTP);
client.getContext().getParameters().add ( "parameter", "value" );
You are not running your client calls inside a org.restlet.Component container
In this case, instantiate manually the client connector and set it to the ClientResource
Client client = new Client(new Context(), Protocol.HTTP);
client.getContext().getParameters().add ( "parameter", "value" );
ClientResource cr = new ClientResource("http://example.com");
cr.setNext(client);
To conclude with, the list of available parameters to be set depends on the kind of client connector you are using (internal connector, based on httpclient, etc)
You can have a look at this page http://restlet.com/learn/guide/2.2/core/base/connectors/.

Related

server failover with Quarkus Reactive MySQL Clients / io.vertx.mysqlclient

Does io.vertx.mysqlclient support server failover as it can be set up with MySQL Connector/J?
My application is based on quarkus using io.vertx.mutiny.mysqlclient.MySQLPool which in turn is based on io.vertx.mysqlclient. If there is support for server failover in that stack, how can it be set up? I did not find any hints in the documentation and code.
No it doesn't support failover.
You could create two clients and then use Munity failover methods to get the same effect:
MySQLPool client1 = ...
MySQLPool client2 = ...
private Uni<List<Data>> query(MySQLPool client) {
// Use client param to send queries to the database
}
Uni<List<Data>> results = query(client1)
.onFailure().recoverWithUni(() -> query(client2));

How to set Eureka URL from code at client application startup

We need to set Eureka server URL at client application from startup code, but it seems there is no way how to do it.
We have a mechanism how to discover Eureka server on network by UDP multicast broadcasting. Server sends response back to the client with information about IP address and port where Eureka server is running. But we don't know how to set this URL in Eureka client application from code. It seems the only way how to set Eureka server URL is the property eureka.client.serviceUrl.defaultZone in application.property file.
// Server - start a new thread with UDP packet detection and reply mechanism
LocationService.listenAndReplyToEurekaClients(thisServerPort);
// Server - application start
SpringApplication.run(EurekaServerApplication.class, args);
// Client - send UDP packet and receive reply with Eureka server IP and port
Response response = LocationService.findEurekaServerAddress(5, 3, TimeUnit.SECONDS);
var hostProtocol = "http";
var eurekaUrl = new URL(
hostProtocol,
response.getEurekaAddress(),
response.getEurekaPort(),"").toString();
We would like to set this eurekaURL to the client before it starts registering to Eureka server.
In this case, we can do following things-
Extend EurekaClientConfigBean and override getEurekaServerServiceUrls method. Method returns a List of String which is nothing but list of all the URLS, of eureka instances. You need to set the URL here from your response which has IP and port.
Later create the discovery client using- DiscoveryClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config). (Its going to be a Bean for sure).
That should work.
You can create ApplicationInfoManager as-
ApplicationInfoManager applicationInfoManager =
initializeApplicationInfoManager(webAppInstanceConfig);
Where WebAppInstanceConfig is-
class WebAppInstanceConfig extends MyDataCenterInstanceConfig {// Override all the needed properties from MyDataCenterInstanceConfig}

Does Jest Client support Cluster name?

I have implemented elasticsearch with native client. This is my implementation:
Settings settings = Settings.settingsBuilder().put("cluster.name", "elasticsearch").build();
TransportClient client = TransportClient.builder().settings(settings).build();
Now I want to implement the same with Jest client. I have created the client, but I am missing cluster name:
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(
new HttpClientConfig
.Builder("http://127.0.0.1:9301")
.multiThreaded(true)
.build()
);
JestClient client = factory.getObject();
Is there any way to implement with cluster name?
Jest uses the HTTP protocol since it's hitting the REST API, hence you don't need to specify the cluster name like you do with the native TransportClient does.
Also make sure to use the port 9201 and not 9301

Restlet Client Internal Connector Error (1002)

I am using a restlet 2.1 client sever based architecture, my client times out within 1 minute after sending the request. and I get the following exception :
Internal Connector Error (1002) - The calling thread timed out while waiting for a response to unblock it.
at org.restlet.resource.ClientResource$1.invoke(ClientResource.java:1663)
at com.sun.proxy.$Proxy17.getTaskList(Unknown Source)....
My code is as below :
import org.restlet.resource.ClientResource;
ClientResource cr = new ClientResource(uri);
MyResource resource= cr.wrap(MyResource .class);
updateStatus = resource.updateData(Parameter);
i also tried this code :
Context context = new Context();
context.getParameters().add("socketTimeout", new String("180000"));
context.getParameters().add("socketConnectTimeoutMs", new String("180000"));
context.getParameters().add("idleTimeout", new String("180000"));
ClientResource cr = new ClientResource(context, url);
TasksResource resource = cr.wrap(TasksResource.class);
how should I configure my client resource to avoid timeout ?
The connection timeout for a Restlet client can be configured at the client connector level. If your call is within a component, you can get the client connector from it (class Client), otherwise you need to instantiate it. Configuring timeout can be done through its parameters (method getContext and then getParameters).
Parameters depend on the underlying connectors (HTTP client, ...).
The following links will help you to fix your issue:
Restlet HTTP Connection Pool
Restlet timeout
Hope it helps you,
Thierry

Apache Thrift tutorial client stuck when using 2 clients - how to make the server multitask?

I'm executing Apache Thrift tutorial for Java.
When running 2 client processes at the same time, the server doesn't accept the 2nd client. Only after the first client finishes, the second one is accepted by the server.
Can anyone explain what's going on?
How can I make the server accept several connections in several threads?
Can anyone explain what's going on?
You already found it out: The TSimpleServer allows only for one connection at a time. It will be available again when the first client disconnects.
How can I make the server accept several connections in several threads?
Use one of the threading servers, whichever fits your use case best.
TThreadPoolServer
TThreadedSelectorServer
TNonBlockingServer
The half-sync/half-async server
Please note, that some of the servers require the client to use TFramedTransport.
Based on other answers, below is the code to enable executing multiple clients simultaneously.
Server (simple):
CalculatorHandler handler = new CalculatorHandler();
Calculator.Processor processor = new Calculator.Processor(handler);
TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(9090);
THsHaServer.Args args = new THsHaServer.Args(serverTransport);
args.processor(processor);
args.transportFactory(new TFramedTransport.Factory());
TServer server = new THsHaServer(args);
server.serve();
Client:
transport = new TSocket("localhost", 9090);
transport.open();
TProtocol protocol = new TBinaryProtocol(new TFramedTransport(transport));
Calculator.Client client = new Calculator.Client(protocol);
perform(client);

Categories

Resources