Skip to content

Commit

Permalink
OverloadMethodsDeclarationOrder fix and fixed Indentation in Hibernat…
Browse files Browse the repository at this point in the history
…e-* classes
  • Loading branch information
Kirill380 committed Sep 28, 2016
1 parent e9f06cb commit 8cc9fe8
Show file tree
Hide file tree
Showing 20 changed files with 1,478 additions and 1,445 deletions.
Expand Up @@ -33,13 +33,15 @@ public byte[] decodeBase64(byte[] base64Data) {
} }


@Override @Override
public byte[] encodeBase64(byte[] binaryData) { public byte[] decodeBase64(String base64String) {
return android.util.Base64.encode(binaryData, android.util.Base64.DEFAULT); return android.util.Base64.decode(base64String, android.util.Base64.DEFAULT);
} }


@Override @Override
public byte[] decodeBase64(String base64String) { public byte[] encodeBase64(byte[] binaryData) {
return android.util.Base64.decode(base64String, android.util.Base64.DEFAULT); return android.util.Base64.encode(binaryData, android.util.Base64.DEFAULT);
} }




} }
Expand Up @@ -231,11 +231,33 @@ private KaaDataChannel getChannel(TransportType type) {
return result; return result;
} }


@Override
public synchronized KaaDataChannel getChannel(String id) {
for (KaaDataChannel channel : channels) {
if (channel.getId().equals(id)) {
return channel;
}
}
return null;
}


@Override @Override
public void sync(TransportType type) { public void sync(TransportType type) {
sync(type, false, false); sync(type, false, false);
} }


private void sync(TransportType type, boolean ack, boolean all) {
LOG.debug("Lookup channel by type {}", type);
KaaDataChannel channel = getChannel(type);
BlockingQueue<SyncTask> queue = syncTaskQueueMap.get(channel.getId());
if (queue != null) {
queue.offer(new SyncTask(type, ack, all));
} else {
LOG.warn("Can't find queue for channel [{}]", channel.getId());
}
}

@Override @Override
public void syncAck(TransportType type) { public void syncAck(TransportType type) {
sync(type, true, false); sync(type, true, false);
Expand All @@ -246,15 +268,7 @@ public void syncAll(TransportType type) {
sync(type, false, true); sync(type, false, true);
} }


@Override
public synchronized KaaDataChannel getChannel(String id) {
for (KaaDataChannel channel : channels) {
if (channel.getId().equals(id)) {
return channel;
}
}
return null;
}


@Override @Override
public synchronized void onTransportConnectionInfoUpdated(TransportConnectionInfo newServer) { public synchronized void onTransportConnectionInfoUpdated(TransportConnectionInfo newServer) {
Expand All @@ -270,8 +284,10 @@ public synchronized void onTransportConnectionInfoUpdated(TransportConnectionInf
} }


for (KaaDataChannel channel : channels) { for (KaaDataChannel channel : channels) {
if (channel.getServerType() == newServer.getServerType() && channel.getTransportProtocolId().equals(newServer.getTransportId())) { if (channel.getServerType() == newServer.getServerType()
LOG.debug("Applying server {} for channel [{}] type {}", newServer, channel.getId(), channel.getTransportProtocolId()); && channel.getTransportProtocolId().equals(newServer.getTransportId())) {
LOG.debug("Applying server {} for channel [{}] type {}",
newServer, channel.getId(), channel.getTransportProtocolId());
channel.setServer(newServer); channel.setServer(newServer);
if (failoverManager != null) { if (failoverManager != null) {
failoverManager.onServerChanged(newServer); failoverManager.onServerChanged(newServer);
Expand Down Expand Up @@ -467,16 +483,6 @@ public void setBootstrapDemultiplexer(KaaDataDemultiplexer demultiplexer) {
this.bootstrapDemultiplexer = demultiplexer; this.bootstrapDemultiplexer = demultiplexer;
} }


private void sync(TransportType type, boolean ack, boolean all) {
LOG.debug("Lookup channel by type {}", type);
KaaDataChannel channel = getChannel(type);
BlockingQueue<SyncTask> queue = syncTaskQueueMap.get(channel.getId());
if (queue != null) {
queue.offer(new SyncTask(type, ack, all));
} else {
LOG.warn("Can't find queue for channel [{}]", channel.getId());
}
}


private void startWorker(KaaDataChannel channel) { private void startWorker(KaaDataChannel channel) {
stopWorker(channel); stopWorker(channel);
Expand Down
Expand Up @@ -84,6 +84,28 @@ public void addNotificationListener(NotificationListener listener) {
} }
} }


@Override
public void addNotificationListener(Long topicId, NotificationListener listener)
throws UnavailableTopicException {
if (listener == null) {
LOG.warn("Failed to add listener: id={}, listener={}", topicId, null);
throw new IllegalArgumentException("Bad listener data");
}

findTopicById(topicId);

synchronized (optionalListeners) {
List<NotificationListener> listeners = optionalListeners.get(topicId);

if (listeners == null) {
listeners = new LinkedList<>();
optionalListeners.put(topicId, listeners);
}

listeners.add(listener);
}
}

@Override @Override
public void removeNotificationListener(NotificationListener listener) { public void removeNotificationListener(NotificationListener listener) {
if (listener == null) { if (listener == null) {
Expand All @@ -96,6 +118,25 @@ public void removeNotificationListener(NotificationListener listener) {
} }
} }


@Override
public void removeNotificationListener(Long topicId, NotificationListener listener)
throws UnavailableTopicException {
if (topicId == null || listener == null) {
LOG.warn("Failed to remove listener: id={}, listener={}", topicId, listener);
throw new IllegalArgumentException("Bad listener data");
}

findTopicById(topicId);

synchronized (optionalListeners) {
List<NotificationListener> listeners = optionalListeners.get(topicId);

if (listeners != null) {
listeners.remove(listener);
}
}
}

@Override @Override
public void addTopicListListener(NotificationTopicListListener listener) { public void addTopicListListener(NotificationTopicListListener listener) {
if (listener == null) { if (listener == null) {
Expand All @@ -120,6 +161,8 @@ public void removeTopicListListener(NotificationTopicListListener listener) {
} }
} }




@Override @Override
public List<Topic> getTopics() { public List<Topic> getTopics() {
List<Topic> topicList = new LinkedList<Topic>(); List<Topic> topicList = new LinkedList<Topic>();
Expand Down Expand Up @@ -149,7 +192,8 @@ public void subscribeToTopic(Long topicId, boolean forceSync) throws Unavailable
} }


@Override @Override
public void subscribeToTopics(List<Long> topicIds, boolean forceSync) throws UnavailableTopicException { public void subscribeToTopics(List<Long> topicIds, boolean forceSync)
throws UnavailableTopicException {
List<SubscriptionCommand> subscriptionUpdate = new LinkedList<>(); List<SubscriptionCommand> subscriptionUpdate = new LinkedList<>();


for (Long id : topicIds) { for (Long id : topicIds) {
Expand All @@ -170,7 +214,8 @@ public void subscribeToTopics(List<Long> topicIds, boolean forceSync) throws Una
} }


@Override @Override
public void unsubscribeFromTopic(Long topicId, boolean forceSync) throws UnavailableTopicException { public void unsubscribeFromTopic(Long topicId, boolean forceSync)
throws UnavailableTopicException {
Topic topic = findTopicById(topicId); Topic topic = findTopicById(topicId);
if (topic.getSubscriptionType() != SubscriptionType.OPTIONAL_SUBSCRIPTION) { if (topic.getSubscriptionType() != SubscriptionType.OPTIONAL_SUBSCRIPTION) {
LOG.warn("Failed to unsubscribe: topic '{}' isn't optional", topicId); LOG.warn("Failed to unsubscribe: topic '{}' isn't optional", topicId);
Expand All @@ -185,7 +230,8 @@ public void unsubscribeFromTopic(Long topicId, boolean forceSync) throws Unavail
} }


@Override @Override
public void unsubscribeFromTopics(List<Long> topicIds, boolean forceSync) throws UnavailableTopicException { public void unsubscribeFromTopics(List<Long> topicIds, boolean forceSync)
throws UnavailableTopicException {
List<SubscriptionCommand> subscriptionUpdate = new LinkedList<>(); List<SubscriptionCommand> subscriptionUpdate = new LinkedList<>();


for (Long id : topicIds) { for (Long id : topicIds) {
Expand All @@ -205,44 +251,7 @@ public void unsubscribeFromTopics(List<Long> topicIds, boolean forceSync) throws
} }
} }


@Override
public void addNotificationListener(Long topicId, NotificationListener listener) throws UnavailableTopicException {
if (listener == null) {
LOG.warn("Failed to add listener: id={}, listener={}", topicId, listener);
throw new IllegalArgumentException("Bad listener data");
}

findTopicById(topicId);

synchronized (optionalListeners) {
List<NotificationListener> listeners = optionalListeners.get(topicId);

if (listeners == null) {
listeners = new LinkedList<>();
optionalListeners.put(topicId, listeners);
}

listeners.add(listener);
}
}

@Override
public void removeNotificationListener(Long topicId, NotificationListener listener) throws UnavailableTopicException {
if (topicId == null || listener == null) {
LOG.warn("Failed to remove listener: id={}, listener={}", topicId, listener);
throw new IllegalArgumentException("Bad listener data");
}

findTopicById(topicId);


synchronized (optionalListeners) {
List<NotificationListener> listeners = optionalListeners.get(topicId);

if (listeners != null) {
listeners.remove(listener);
}
}
}


@Override @Override
public void sync() { public void sync() {
Expand Down Expand Up @@ -301,22 +310,27 @@ public void notificationReceived(List<Notification> notifications) throws IOExce
notifyListeners(mandatoryListeners, topic, notification); notifyListeners(mandatoryListeners, topic, notification);
} }
} }
} catch (UnavailableTopicException e) { } catch (UnavailableTopicException ex) {
LOG.warn("Received notification for an unknown topic (id={}), exception catched: {}", notification.getTopicId(), e); LOG.warn("Received notification for an unknown topic (id={}), exception catched: {}",
notification.getTopicId(), ex);
} }
} }
} }


private void notifyListeners(Collection<NotificationListener> listeners, final Topic topic, final Notification notification) { private void notifyListeners(Collection<NotificationListener> listeners, final Topic topic,
final Notification notification) {
final Collection<NotificationListener> listenersCopy = new ArrayList<NotificationListener>(listeners); final Collection<NotificationListener> listenersCopy = new ArrayList<NotificationListener>(listeners);
if (notification.getBody() != null) { if (notification.getBody() != null) {
executorContext.getCallbackExecutor().submit(new Runnable() { executorContext.getCallbackExecutor().submit(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
deserializer.notify(Collections.unmodifiableCollection(listenersCopy), topic, notification.getBody().array()); deserializer.notify(
} catch (IOException e) { Collections.unmodifiableCollection(listenersCopy),
LOG.error("Failed to process notification for topic {}", topic.getId(), e); topic,
notification.getBody().array());
} catch (IOException ex) {
LOG.error("Failed to process notification for topic {}", topic.getId(), ex);
} }
} }
}); });
Expand Down
Expand Up @@ -33,13 +33,15 @@ public byte[] decodeBase64(byte[] base64Data) {
} }


@Override @Override
public byte[] encodeBase64(byte[] binaryData) { public byte[] decodeBase64(String base64String) {
return org.apache.commons.codec.binary.Base64.encodeBase64(binaryData); return org.apache.commons.codec.binary.Base64.decodeBase64(base64String);
} }


@Override @Override
public byte[] decodeBase64(String base64String) { public byte[] encodeBase64(byte[] binaryData) {
return org.apache.commons.codec.binary.Base64.decodeBase64(base64String); return org.apache.commons.codec.binary.Base64.encodeBase64(binaryData);
} }




} }
Expand Up @@ -135,9 +135,9 @@ static Signature signatureForAlgorithm(String algorithm) {
public static String bytesToHex(byte[] bytes) { public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 3]; char[] hexChars = new char[bytes.length * 3];
for (int j = 0; j < bytes.length; j++) { for (int j = 0; j < bytes.length; j++) {
int v = bytes[j] & 0xFF; int value = bytes[j] & 0xFF;
hexChars[j * 3] = HEX_ARRAY[v >>> 4]; hexChars[j * 3] = HEX_ARRAY[value >>> 4];
hexChars[j * 3 + 1] = HEX_ARRAY[v & 0x0F]; hexChars[j * 3 + 1] = HEX_ARRAY[value & 0x0F];
hexChars[j * 3 + 2] = ' '; hexChars[j * 3 + 2] = ' ';
} }
return new String(hexChars); return new String(hexChars);
Expand Down Expand Up @@ -170,21 +170,10 @@ public byte[] encodeData(byte[] message) throws GeneralSecurityException {
return sessionCipherPair.encCipher.doFinal(message); return sessionCipherPair.encCipher.doFinal(message);
} }


/**
* Decode data using session key then is decoded using private key.
*
* @param message the message
* @param encodedKey the encoded key
* @return the byte[]
* @throws GeneralSecurityException the general security exception
*/
public byte[] decodeData(byte[] message, byte[] encodedKey) throws GeneralSecurityException {
sessionCipherPair = null;
decodeSessionKey(encodedKey);
return decodeData(message);
}


private void decodeSessionKey(byte[] encodedKey) throws InvalidKeyException, IllegalBlockSizeException, private void decodeSessionKey(byte[] encodedKey) throws
InvalidKeyException,
IllegalBlockSizeException,
BadPaddingException { BadPaddingException {
Cipher sessionKeyCipher = RSA_CIPHER.get(); Cipher sessionKeyCipher = RSA_CIPHER.get();
sessionKeyCipher.init(Cipher.DECRYPT_MODE, privateKey); sessionKeyCipher.init(Cipher.DECRYPT_MODE, privateKey);
Expand All @@ -206,6 +195,21 @@ public byte[] decodeData(byte[] message) throws GeneralSecurityException {
return sessionCipherPair.decCipher.doFinal(message); return sessionCipherPair.decCipher.doFinal(message);
} }



/**
* Decode data using session key then is decoded using private key.
*
* @param message the message
* @param encodedKey the encoded key
* @return the byte[]
* @throws GeneralSecurityException the general security exception
*/
public byte[] decodeData(byte[] message, byte[] encodedKey) throws GeneralSecurityException {
sessionCipherPair = null;
decodeSessionKey(encodedKey);
return decodeData(message);
}

/** /**
* Sign message using private key. * Sign message using private key.
* *
Expand Down

0 comments on commit 8cc9fe8

Please sign in to comment.