use of io.joynr.exceptions.JoynrIllegalStateException in project joynr by bmwcarit.
the class ProxyBuilderDefaultImpl method createProxyInvocationHandler.
// Method called by both synchronous and asynchronous build() to create a ProxyInvocationHandler
private ProxyInvocationHandler createProxyInvocationHandler(final ProxyCreatedCallback<T> callback) {
if (buildCalled) {
throw new JoynrIllegalStateException("Proxy builder was already used to build a proxy. Please create a new proxy builder for each proxy.");
}
buildCalled = true;
final ProxyInvocationHandler proxyInvocationHandler = proxyInvocationHandlerFactory.create(domains, interfaceName, proxyParticipantId, discoveryQos, messagingQos);
// This order is necessary because the Arbitrator might return early
// But if the listener is set after the ProxyInvocationHandler the
// Arbitrator cannot return early
arbitrator.setArbitrationListener(new ArbitrationCallback() {
@Override
public void onSuccess(ArbitrationResult arbitrationResult) {
logger.debug("DISCOVERY proxy created for:{}", arbitrationResult.getDiscoveryEntries());
proxyInvocationHandler.createConnector(arbitrationResult);
callback.onProxyCreationFinished(proxy);
}
@Override
public void onError(Throwable throwable) {
JoynrRuntimeException reason;
if (throwable instanceof JoynrRuntimeException) {
reason = (JoynrRuntimeException) throwable;
} else {
reason = new JoynrRuntimeException(throwable);
}
proxyInvocationHandler.abort(reason);
callback.onProxyCreationError(reason);
}
});
return proxyInvocationHandler;
}
use of io.joynr.exceptions.JoynrIllegalStateException in project joynr by bmwcarit.
the class ConnectorTest method subscriptionMethodCallWithNoExpiryDate.
@Test
public void subscriptionMethodCallWithNoExpiryDate() throws JoynrIllegalStateException {
ConnectorInvocationHandler connector = createConnector();
assertNotNull(connector);
try {
Future<String> future = new Future<String>();
String subscriptionId = "subscriptionId";
PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
subscriptionQos.setPeriodMs(1000).setExpiryDateMs(0).setAlertAfterIntervalMs(1000);
AttributeSubscriptionListener<GpsPosition> listener = new AttributeSubscriptionAdapter<GpsPosition>();
Object[] args = new Object[] { listener, subscriptionQos, subscriptionId };
Method method = LocalisationSubscriptionInterface.class.getDeclaredMethod("subscribeToGPSPosition", String.class, AttributeSubscriptionListener.class, SubscriptionQos.class);
AttributeSubscribeInvocation attributeSubscription = new AttributeSubscribeInvocation(method, args, future);
connector.executeSubscriptionMethod(attributeSubscription);
verify(subscriptionManager, times(1)).registerAttributeSubscription(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), eq(attributeSubscription));
} catch (Exception e) {
// This is what is supposed to happen -> no error handling
fail("Calling a subscription method with no expiry date throws an exception.");
}
}
use of io.joynr.exceptions.JoynrIllegalStateException in project joynr by bmwcarit.
the class OwnerAccessControlEntryManager method findByUserIdDomainInterfaceNameAndOperation.
private OwnerAccessControlEntryEntity findByUserIdDomainInterfaceNameAndOperation(String userId, String domain, String interfaceName, String operation) {
OwnerAccessControlEntryEntity entity = null;
Query query = entityManager.createQuery("select oace from OwnerAccessControlEntryEntity oace where " + "oace.userId = :userId and oace.domain = :domain and oace.interfaceName = :interfaceName " + "and oace.operation = :operation", OwnerAccessControlEntryEntity.class);
query.setParameter("userId", userId);
query.setParameter("domain", domain);
query.setParameter("interfaceName", interfaceName);
query.setParameter("operation", operation);
List<OwnerAccessControlEntryEntity> resultList = query.getResultList();
if (resultList.size() == 1) {
entity = resultList.get(0);
} else if (resultList.size() > 1) {
throw new JoynrIllegalStateException(format("Too many results found for %s for userId / domain / interfaceName / operation: %s / %s / %s / %s", OwnerAccessControlEntryEntity.class.getSimpleName(), userId, domain, interfaceName, operation));
}
return entity;
}
use of io.joynr.exceptions.JoynrIllegalStateException in project joynr by bmwcarit.
the class OwnerRegistrationControlEntryManager method findByUserIdDomainAndInterfaceName.
private OwnerRegistrationControlEntryEntity findByUserIdDomainAndInterfaceName(String userId, String domain, String interfaceName) {
Query query = entityManager.createQuery("select orce from OwnerRegistrationControlEntryEntity orce " + "where orce.userId = :userId and orce.domain = :domain and orce.interfaceName = :interfaceName", OwnerRegistrationControlEntryEntity.class);
query.setParameter("userId", userId);
query.setParameter("domain", domain);
query.setParameter("interfaceName", interfaceName);
List<OwnerRegistrationControlEntryEntity> resultList = query.getResultList();
OwnerRegistrationControlEntryEntity entity = null;
if (resultList.size() == 1) {
entity = resultList.get(0);
} else if (resultList.size() > 1) {
throw new JoynrIllegalStateException(format("Too many results found for %s for userId / domain / interfaceName / operation: %s / %s / %s", OwnerRegistrationControlEntryEntity.class.getSimpleName(), userId, domain, interfaceName));
}
return entity;
}
use of io.joynr.exceptions.JoynrIllegalStateException in project joynr by bmwcarit.
the class JoynrMessagingConnectorInvocationHandler method executeOneWayMethod.
@Override
public void executeOneWayMethod(Method method, Object[] args) {
// TODO does a method with 0 args pass in an empty args array, or null for args?
if (method == null) {
throw new IllegalArgumentException("Method cannot be null");
}
if (toDiscoveryEntries.isEmpty()) {
throw new JoynrIllegalStateException("You must have at least one participant to be able to execute an oneWayMethod.");
}
logger.debug("ONEWAYREQUEST call proxy: method: {}, params: {}, proxy participantId: {}," + " provider discovery entries: {}", method.getName(), args, fromParticipantId, toDiscoveryEntries);
OneWayRequest request = new OneWayRequest(method.getName(), args, method.getParameterTypes());
requestReplyManager.sendOneWayRequest(fromParticipantId, toDiscoveryEntries, request, qosSettings);
}
Aggregations