Project

General

Profile

« Previous | Next » 

Revision 46452

async method thread

View differences:

BaseService.java
27 27
import eu.dnetlib.enabling.annotations.DnetService;
28 28
import eu.dnetlib.enabling.annotations.DnetServiceType;
29 29
import eu.dnetlib.exceptions.DnetGenericException;
30
import eu.dnetlib.exceptions.DnetGenericRuntimeException;
30 31
import eu.dnetlib.services.async.AsyncClientUtils;
31
import eu.dnetlib.services.async.AsyncMethodException;
32 32
import eu.dnetlib.services.async.AsyncResponse;
33 33
import eu.dnetlib.services.async.HasAsyncMethods;
34 34
import eu.dnetlib.services.async.ResponseAck;
......
116 116

  
117 117
		if (this instanceof HasAsyncMethods) {
118 118

  
119
			try {
120
				final String id = "invocation-" + UUID.randomUUID();
121
				final String url = clientBaseUrl + "/async/response/" + id;
122
				final RestTemplate restTemplate = new RestTemplate();
119
			final String id = "invocation-" + UUID.randomUUID();
120
			final String url = clientBaseUrl + "/async/response/" + id;
121
			final RestTemplate restTemplate = new RestTemplate();
123 122

  
124
				((HasAsyncMethods) this).processMethod(method, jsonParams, res -> restTemplate.postForObject(url, res, ResponseAckStatus.class));
123
			new Thread(() -> {
124
				try {
125
					((HasAsyncMethods) this).processMethod(method, jsonParams, res -> restTemplate.postForObject(url, res, ResponseAckStatus.class));
126
				} catch (final Exception e) {
127
					log.error("Invocation of async method failed", e);
128
					throw new DnetGenericRuntimeException("Invocation of async method failed", e);
129
				}
130
			}).start();
125 131

  
126
				return id;
127
			} catch (final AsyncMethodException e) {
128
				log.error("Invocation of async method failed", e);
129
				throw e;
130
			}
132
			return id;
131 133

  
132 134
		} else {
133 135
			log.error("Service " + getServiceType() + " does not implement HasAsyncMethods interface");

Also available in: Unified diff