Skip to content

Commit

Permalink
KAA-1279: Fixed about 50 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sashadidukh committed Sep 29, 2016
1 parent d249d6d commit 1d235a5
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 52 deletions.
Expand Up @@ -38,7 +38,8 @@
@Generated("BaseKaaClient.java.template") @Generated("BaseKaaClient.java.template")
public class BaseKaaClient extends AbstractKaaClient implements KaaClient { public class BaseKaaClient extends AbstractKaaClient implements KaaClient {


public BaseKaaClient(KaaClientPlatformContext context, KaaClientStateListener listener, boolean isAutogeneratedKeys) public BaseKaaClient(KaaClientPlatformContext context, KaaClientStateListener listener,
boolean isAutogeneratedKeys)
throws IOException, GeneralSecurityException { throws IOException, GeneralSecurityException {
super(context, listener, isAutogeneratedKeys); super(context, listener, isAutogeneratedKeys);
} }
Expand Down
Expand Up @@ -52,9 +52,9 @@ public interface KaaClient extends GenericKaaClient {
/** /**
* Adds new log record to local storage. * Adds new log record to local storage.
* *
* @param record A log record object. * @param record the log record object.
* @return The {@link RecordFuture} object which allows tracking a delivery status of a log * @return the {@link RecordFuture} object which allows tracking a delivery status of
* record. * a log record
*/ */
RecordFuture addLogRecord(Log record); RecordFuture addLogRecord(Log record);


Expand Down
Expand Up @@ -125,7 +125,7 @@ public void onGenericEvent(final String eventFqn, final byte[] data, final Strin
LOG.info("Received event [eventClassFQN: {}]", eventFqn); LOG.info("Received event [eventClassFQN: {}]", eventFqn);
for (final EventFamily family : registeredEventFamilies) { for (final EventFamily family : registeredEventFamilies) {
LOG.info("Lookup event fqn {} in family {}", eventFqn, family); LOG.info("Lookup event fqn {} in family {}", eventFqn, family);
if (family.getSupportedEventFQNs().contains(eventFqn)) { if (family.getSupportedEventFqns().contains(eventFqn)) {
LOG.info("Event fqn {} found in family {}", eventFqn, family); LOG.info("Event fqn {} found in family {}", eventFqn, family);
executorContext.getCallbackExecutor().submit(new Runnable() { executorContext.getCallbackExecutor().submit(new Runnable() {
@Override @Override
Expand All @@ -138,9 +138,9 @@ public void run() {
} }


@Override @Override
public int findEventListeners(List<String> eventClassFQNs, FindEventListenersCallback listener) { public int findEventListeners(List<String> eventFqns, FindEventListenersCallback listener) {
int requestId = new Random().nextInt(); int requestId = new Random().nextInt();
EventListenersRequest request = new EventListenersRequest(requestId, eventClassFQNs); EventListenersRequest request = new EventListenersRequest(requestId, eventFqns);
EventListenersRequestBinding bind = new EventListenersRequestBinding(listener, request); EventListenersRequestBinding bind = new EventListenersRequestBinding(listener, request);
eventListenersRequests.put(requestId, bind); eventListenersRequests.put(requestId, bind);
LOG.debug("Adding event listener resolution request. Request ID: {}", requestId); LOG.debug("Adding event listener resolution request. Request ID: {}", requestId);
Expand Down
Expand Up @@ -27,18 +27,18 @@
public interface EventFamily { public interface EventFamily {


/** /**
* Returns set of supported incoming events in event family * Returns set of supported incoming events in event family.
* *
* @return set of supported events presented as set event fully qualified names * @return set of supported events presented as set event fully qualified names
*/ */
Set<String> getSupportedEventFQNs(); Set<String> getSupportedEventFqns();


/** /**
* Generic handler of event received from server. * Generic handler of event received from server.
* *
* @param eventFQN Fully qualified name of an event * @param eventFqn Fully qualified name of an event
* @param data Event data * @param data Event data
* @param source Event source * @param source Event source
*/ */
void onGenericEvent(String eventFQN, byte[] data, String source); void onGenericEvent(String eventFqn, byte[] data, String source);
} }
Expand Up @@ -25,9 +25,7 @@
* events' fully-qualified names.<br> * events' fully-qualified names.<br>
* <b>NOTE:</b> Operations server will respond with list of endpoints which * <b>NOTE:</b> Operations server will respond with list of endpoints which
* can receive <b>ALL</b> listed event types (FQNs). * can receive <b>ALL</b> listed event types (FQNs).
*
* For example: * For example:
*
* <pre> * <pre>
* {@code * {@code
* List<String> fqnsToBeSupported = new ArrayList<String>(); * List<String> fqnsToBeSupported = new ArrayList<String>();
Expand Down Expand Up @@ -56,9 +54,9 @@ public interface EventListenersResolver {
/** /**
* Submits an event listeners resolution request * Submits an event listeners resolution request
* *
* @param eventFQNs List of event class FQNs which have to be supported by endpoint. * @param eventFqns List of event class FQNs which have to be supported by endpoint.
* @param listener Result listener {@link FindEventListenersCallback}} * @param listener Result listener {@link FindEventListenersCallback}}
* @return Request ID of submitted request * @return Request ID of submitted request
*/ */
int findEventListeners(List<String> eventFQNs, FindEventListenersCallback listener); int findEventListeners(List<String> eventFqns, FindEventListenersCallback listener);
} }
Expand Up @@ -107,7 +107,7 @@ public interface EventManager extends EventListenersResolver, Transactable {
void clearState(); void clearState();


/** /**
* Restrict manager to use data channel until {@link #releaseDataChannel()} called * Restrict manager to use data channel until {@link #releaseDataChannel()} called.
*/ */
void engageDataChannel(); void engageDataChannel();


Expand Down
Expand Up @@ -103,8 +103,8 @@
* <h3>Searching for event recipients</h3> * <h3>Searching for event recipients</h3>
* <pre> * <pre>
* {@code * {@code
* Kaa.getClient().getEventListenersResolver().findEventListeners(Arrays.asList("org.kaa.example.events.TestEvent"), * Kaa.getClient().getEventListenersResolver().findEventListeners(Arrays.asList(
* new FetchEventListeners() { * "org.kaa.example.events.TestEvent"),new FetchEventListeners() {
* \@Override * \@Override
* public void onEventListenersReceived(List<String> eventListeners) { * public void onEventListenersReceived(List<String> eventListeners) {
* // process response * // process response
Expand Down
Expand Up @@ -22,13 +22,14 @@
import java.util.Map; import java.util.Map;


/** /**
* Callback interface for attached endpoint list change notifications * Callback interface for attached endpoint list change notifications.
* *
* @author Taras Lemkin * @author Taras Lemkin
*/ */
public interface ChangedAttachedEndpointListCallback { public interface ChangedAttachedEndpointListCallback {

/** /**
* Callback on attached endpoints list changed * Callback on attached endpoints list changed.
* *
* @param attachedEndpoints the attached endpoints * @param attachedEndpoints the attached endpoints
* @see EndpointAccessToken * @see EndpointAccessToken
Expand Down
Expand Up @@ -44,16 +44,21 @@
* *
* @author Taras Lemkin * @author Taras Lemkin
*/ */
public class DefaultEndpointRegistrationManager implements EndpointRegistrationManager, EndpointRegistrationProcessor { public class DefaultEndpointRegistrationManager implements EndpointRegistrationManager,
EndpointRegistrationProcessor {


private static final Logger LOG = LoggerFactory.getLogger(DefaultEndpointRegistrationManager.class); private static final Logger LOG = LoggerFactory.getLogger(
DefaultEndpointRegistrationManager.class);
private static final Random RANDOM = new Random(); private static final Random RANDOM = new Random();


private final KaaClientState state; private final KaaClientState state;
private final Map<Integer, OnAttachEndpointOperationCallback> endpointAttachListeners = new ConcurrentHashMap<>(); private final Map<Integer, OnAttachEndpointOperationCallback> endpointAttachListeners =
private final Map<Integer, OnDetachEndpointOperationCallback> endpointDetachListeners = new ConcurrentHashMap<>(); new ConcurrentHashMap<>();
private final Map<Integer, OnDetachEndpointOperationCallback> endpointDetachListeners =
new ConcurrentHashMap<>();


private final Map<Integer, EndpointAccessToken> attachEndpointRequests = new ConcurrentHashMap<>(); private final Map<Integer, EndpointAccessToken> attachEndpointRequests =
new ConcurrentHashMap<>();
private final Map<Integer, EndpointKeyHash> detachEndpointRequests = new ConcurrentHashMap<>(); private final Map<Integer, EndpointKeyHash> detachEndpointRequests = new ConcurrentHashMap<>();
private final ExecutorContext executorContext; private final ExecutorContext executorContext;
private UserAttachRequest userAttachRequest; private UserAttachRequest userAttachRequest;
Expand All @@ -63,7 +68,8 @@ public class DefaultEndpointRegistrationManager implements EndpointRegistrationM
private volatile UserTransport userTransport; private volatile UserTransport userTransport;
private volatile ProfileTransport profileTransport; private volatile ProfileTransport profileTransport;


public DefaultEndpointRegistrationManager(KaaClientState state, ExecutorContext executorContext, UserTransport userTransport, public DefaultEndpointRegistrationManager(KaaClientState state, ExecutorContext executorContext,
UserTransport userTransport,
ProfileTransport profileTransport) { ProfileTransport profileTransport) {
this.userTransport = userTransport; this.userTransport = userTransport;
this.profileTransport = profileTransport; this.profileTransport = profileTransport;
Expand Down Expand Up @@ -93,7 +99,8 @@ public String refreshEndpointAccessToken() {
} }


@Override @Override
public void attachEndpoint(EndpointAccessToken endpointAccessToken, OnAttachEndpointOperationCallback resultListener) { public void attachEndpoint(EndpointAccessToken endpointAccessToken,
OnAttachEndpointOperationCallback resultListener) {
int requestId = getRandomInt(); int requestId = getRandomInt();
LOG.info("Going to attach Endpoint by access token: {}", endpointAccessToken); LOG.info("Going to attach Endpoint by access token: {}", endpointAccessToken);
attachEndpointRequests.put(requestId, endpointAccessToken); attachEndpointRequests.put(requestId, endpointAccessToken);
Expand All @@ -106,7 +113,8 @@ public void attachEndpoint(EndpointAccessToken endpointAccessToken, OnAttachEndp
} }


@Override @Override
public void detachEndpoint(EndpointKeyHash endpointKeyHash, OnDetachEndpointOperationCallback resultListener) { public void detachEndpoint(
EndpointKeyHash endpointKeyHash, OnDetachEndpointOperationCallback resultListener) {
int requestId = getRandomInt(); int requestId = getRandomInt();
LOG.info("Going to detach Endpoint by endpoint key hash: {}", endpointKeyHash); LOG.info("Going to detach Endpoint by endpoint key hash: {}", endpointKeyHash);
detachEndpointRequests.put(requestId, endpointKeyHash); detachEndpointRequests.put(requestId, endpointKeyHash);
Expand All @@ -119,16 +127,20 @@ public void detachEndpoint(EndpointKeyHash endpointKeyHash, OnDetachEndpointOper
} }


@Override @Override
public void attachUser(String userExternalId, String userAccessToken, UserAttachCallback callback) { public void attachUser(
String userExternalId, String userAccessToken, UserAttachCallback callback) {
if (UserVerifierConstants.DEFAULT_USER_VERIFIER_TOKEN != null) { if (UserVerifierConstants.DEFAULT_USER_VERIFIER_TOKEN != null) {
attachUser(UserVerifierConstants.DEFAULT_USER_VERIFIER_TOKEN, userExternalId, userAccessToken, callback); attachUser(UserVerifierConstants.DEFAULT_USER_VERIFIER_TOKEN, userExternalId,
userAccessToken, callback);
} else { } else {
throw new IllegalStateException("Default user verifier was not defined during SDK generation process!"); throw new IllegalStateException(
"Default user verifier was not defined during SDK generation process!");
} }
} }


@Override @Override
public void attachUser(String userVerifierToken, String userExternalId, String userAccessToken, UserAttachCallback callback) { public void attachUser(String userVerifierToken, String userExternalId, String userAccessToken,
UserAttachCallback callback) {
userAttachRequest = new UserAttachRequest(userVerifierToken, userExternalId, userAccessToken); userAttachRequest = new UserAttachRequest(userVerifierToken, userExternalId, userAccessToken);
userAttachCallback = callback; userAttachCallback = callback;
if (userTransport != null) { if (userTransport != null) {
Expand All @@ -141,8 +153,10 @@ public Map<EndpointAccessToken, EndpointKeyHash> getAttachedEndpointList() {
} }


@Override @Override
public void onUpdate(List<EndpointAttachResponse> attachResponses, List<EndpointDetachResponse> detachResponses, public void onUpdate(List<EndpointAttachResponse> attachResponses,
final UserAttachResponse userResponse, final UserAttachNotification userAttachNotification, List<EndpointDetachResponse> detachResponses,
final UserAttachResponse userResponse,
final UserAttachNotification userAttachNotification,
final UserDetachNotification userDetachNotification) throws IOException { final UserDetachNotification userDetachNotification) throws IOException {
if (userResponse != null) { if (userResponse != null) {
if (userAttachCallback != null) { if (userAttachCallback != null) {
Expand All @@ -163,7 +177,8 @@ public void run() {
executorContext.getCallbackExecutor().submit(new Runnable() { executorContext.getCallbackExecutor().submit(new Runnable() {
@Override @Override
public void run() { public void run() {
callback.onAttachedToUser(userAttachRequest.getUserExternalId(), state.getEndpointAccessToken()); callback.onAttachedToUser(userAttachRequest.getUserExternalId(),
state.getEndpointAccessToken());
} }
}); });
} }
Expand All @@ -173,14 +188,16 @@ public void run() {


if (attachResponses != null && !attachResponses.isEmpty()) { if (attachResponses != null && !attachResponses.isEmpty()) {
for (EndpointAttachResponse attached : attachResponses) { for (EndpointAttachResponse attached : attachResponses) {
notifyAttachedListener(attached.getResult(), endpointAttachListeners.remove(attached.getRequestId()), new EndpointKeyHash( notifyAttachedListener(attached.getResult(),
endpointAttachListeners.remove(attached.getRequestId()), new EndpointKeyHash(
attached.getEndpointKeyHash())); attached.getEndpointKeyHash()));
attachEndpointRequests.remove(attached.getRequestId()); attachEndpointRequests.remove(attached.getRequestId());
} }
} }
if (detachResponses != null && !detachResponses.isEmpty()) { if (detachResponses != null && !detachResponses.isEmpty()) {
for (EndpointDetachResponse detached : detachResponses) { for (EndpointDetachResponse detached : detachResponses) {
notifyDetachedListener(detached.getResult(), endpointDetachListeners.remove(detached.getRequestId())); notifyDetachedListener(detached.getResult(),
endpointDetachListeners.remove(detached.getRequestId()));
EndpointKeyHash endpointKeyHash = detachEndpointRequests.remove(detached.getRequestId()); EndpointKeyHash endpointKeyHash = detachEndpointRequests.remove(detached.getRequestId());
if (endpointKeyHash != null && detached.getResult() == SyncResponseResultType.SUCCESS) { if (endpointKeyHash != null && detached.getResult() == SyncResponseResultType.SUCCESS) {
if (endpointKeyHash.equals(state.getEndpointKeyHash())) { if (endpointKeyHash.equals(state.getEndpointKeyHash())) {
Expand Down Expand Up @@ -218,7 +235,8 @@ public void run() {
} }
} }


private void notifyAttachedListener(final SyncResponseResultType result, final OnAttachEndpointOperationCallback operationCallback, private void notifyAttachedListener(final SyncResponseResultType result,
final OnAttachEndpointOperationCallback operationCallback,
final EndpointKeyHash keyHash) { final EndpointKeyHash keyHash) {
if (operationCallback != null) { if (operationCallback != null) {
executorContext.getCallbackExecutor().submit(new Runnable() { executorContext.getCallbackExecutor().submit(new Runnable() {
Expand All @@ -230,7 +248,8 @@ public void run() {
} }
} }


private void notifyDetachedListener(final SyncResponseResultType result, final OnDetachEndpointOperationCallback operationCallback) { private void notifyDetachedListener(final SyncResponseResultType result,
final OnDetachEndpointOperationCallback operationCallback) {
if (operationCallback != null) { if (operationCallback != null) {
executorContext.getCallbackExecutor().submit(new Runnable() { executorContext.getCallbackExecutor().submit(new Runnable() {
@Override @Override
Expand Down
Expand Up @@ -84,17 +84,19 @@ public interface EndpointRegistrationManager {
* @see EndpointAccessToken * @see EndpointAccessToken
* @see OnAttachEndpointOperationCallback * @see OnAttachEndpointOperationCallback
*/ */
void attachEndpoint(EndpointAccessToken endpointAccessToken, OnAttachEndpointOperationCallback resultListener); void attachEndpoint(EndpointAccessToken endpointAccessToken,
OnAttachEndpointOperationCallback resultListener);


/** /**
* Updates with new endpoint detach request * Updates with new endpoint detach request.
* *
* @param endpointKeyHash Key hash of the detaching endpoint * @param endpointKeyHash Key hash of the detaching endpoint
* @param resultListener Listener to notify about result of the enpoint attaching * @param resultListener Listener to notify about result of the enpoint attaching
* @see EndpointKeyHash * @see EndpointKeyHash
* @see OnDetachEndpointOperationCallback * @see OnDetachEndpointOperationCallback
*/ */
void detachEndpoint(EndpointKeyHash endpointKeyHash, OnDetachEndpointOperationCallback resultListener); void detachEndpoint(EndpointKeyHash endpointKeyHash,
OnDetachEndpointOperationCallback resultListener);


/** /**
* Creates user attach request using default verifier. Default verifier is selected during SDK * Creates user attach request using default verifier. Default verifier is selected during SDK
Expand All @@ -117,7 +119,8 @@ public interface EndpointRegistrationManager {
* @param callback called when authentication result received * @param callback called when authentication result received
* @see UserAttachCallback * @see UserAttachCallback
*/ */
void attachUser(String userVerifierToken, String userExternalId, String userAccessToken, UserAttachCallback callback); void attachUser(String userVerifierToken, String userExternalId, String userAccessToken,
UserAttachCallback callback);


/** /**
* Checks if current endpoint is attached to user. * Checks if current endpoint is attached to user.
Expand All @@ -127,15 +130,15 @@ public interface EndpointRegistrationManager {
boolean isAttachedToUser(); boolean isAttachedToUser();


/** /**
* Sets callback for notifications when current endpoint is attached to user * Sets callback for notifications when current endpoint is attached to user.
* *
* @param callback the callback * @param callback the callback
* @see AttachEndpointToUserCallback * @see AttachEndpointToUserCallback
*/ */
void setAttachedCallback(AttachEndpointToUserCallback callback); void setAttachedCallback(AttachEndpointToUserCallback callback);


/** /**
* Sets callback for notifications when current endpoint is detached from user * Sets callback for notifications when current endpoint is detached from user.
* *
* @param callback the callback * @param callback the callback
* @see DetachEndpointFromUserCallback * @see DetachEndpointFromUserCallback
Expand Down
Expand Up @@ -24,7 +24,6 @@
* Callback interface for attached endpoint notifications.<br> * Callback interface for attached endpoint notifications.<br>
* <br> * <br>
* Use this interface to receive result of next operations: * Use this interface to receive result of next operations:
*
* Attach endpoint to user by {@link EndpointAccessToken} * Attach endpoint to user by {@link EndpointAccessToken}
* <br> * <br>
* Once result from Operations server is received, listener is notified with * Once result from Operations server is received, listener is notified with
Expand Down
Expand Up @@ -28,12 +28,14 @@
* registered. </p> <h2>Usage</h2> <p> Attaching current endpoint to user: * registered. </p> <h2>Usage</h2> <p> Attaching current endpoint to user:
* <pre> * <pre>
* {@code * {@code
* EndpointRegistrationManager registrationManager = kaaClient.getEndpointRegistrationManager(); * EndpointRegistrationManager registrationManager =
* kaaClient.getEndpointRegistrationManager();
* registrationManager.attachUser("userExternalId", "userAccessToken", new * registrationManager.attachUser("userExternalId", "userAccessToken", new
* UserAuthResultListener() { ... }); * UserAuthResultListener() { ... });
* } * }
* </pre> * </pre>
* To check if this endpoint is attached to user call {@link org.kaaproject.kaa.client.event.registration.EndpointRegistrationManager#isAttachedToUser()}.<br> * To check if this endpoint is attached to user call {@link
* org.kaaproject.kaa.client.event.registration.EndpointRegistrationManager#isAttachedToUser()}.<br>
* <br> Attaching any endpoint to user by its access token: * <br> Attaching any endpoint to user by its access token:
* <pre> * <pre>
* {@code * {@code
Expand All @@ -52,7 +54,8 @@
* </pre> * </pre>
* EndpointKeyHash for endpoint can be received with AttachEndpoint operation provided from * EndpointKeyHash for endpoint can be received with AttachEndpoint operation provided from
* Operations server. <br> <br> If current endpoint is assumed to be attached or detached by another * Operations server. <br> <br> If current endpoint is assumed to be attached or detached by another
* endpoint, specific {@link org.kaaproject.kaa.client.event.registration.AttachEndpointToUserCallback} * endpoint, specific {@link
* org.kaaproject.kaa.client.event.registration.AttachEndpointToUserCallback}
* and {@link org.kaaproject.kaa.client.event.registration.DetachEndpointFromUserCallback} may be * and {@link org.kaaproject.kaa.client.event.registration.DetachEndpointFromUserCallback} may be
* specified to receive notification about such event.<br> <br> * specified to receive notification about such event.<br> <br>
*/ */
Expand Down
Expand Up @@ -64,7 +64,7 @@ public void testNoHandler() throws IOException {
eventManager.registerEventFamily(eventFamily); eventManager.registerEventFamily(eventFamily);
eventManager.produceEvent("kaa.test.event.PlayEvent", new byte[0], null); eventManager.produceEvent("kaa.test.event.PlayEvent", new byte[0], null);
Mockito.verify(transport, times(1)).sync(); Mockito.verify(transport, times(1)).sync();
verify(eventFamily, times(0)).getSupportedEventFQNs(); verify(eventFamily, times(0)).getSupportedEventFqns();
verify(eventFamily, times(0)).onGenericEvent(anyString(), any(byte[].class), anyString()); verify(eventFamily, times(0)).onGenericEvent(anyString(), any(byte[].class), anyString());
} }


Expand Down Expand Up @@ -244,12 +244,12 @@ public ConcreteEventFamily(String supportedFQN) {
} }


@Override @Override
public Set<String> getSupportedEventFQNs() { public Set<String> getSupportedEventFqns() {
return supportedEventFQNs; return supportedEventFQNs;
} }


@Override @Override
public void onGenericEvent(String eventFQN, byte[] data, String source) { public void onGenericEvent(String eventFqn, byte[] data, String source) {
eventsCount++; eventsCount++;
} }


Expand Down

0 comments on commit 1d235a5

Please sign in to comment.