Fix or suppress Hazelcast-related "unchecked" compilation warnings.
* Fix compilation warnings in file HazelcastEventChannel.java
that were related to using the Java generics.
* Suppress "unchecked" compilation warnings in file HazelcastDatagrid.java
There was no obvious solution of solving the problem, hence for the time
being the warnings are suppressed.
* Minor refactoring inside file HazelcastDatagrid.java to allow
using the @SuppressWarnings("unchecked") statement inline.
Change-Id: I89ff9b4306b75ac7798ccf8b31daca3a825dc512
diff --git a/src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java b/src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java
index e204e45..563be33 100755
--- a/src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java
+++ b/src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java
@@ -202,27 +202,28 @@
private <K, V> IEventChannel<K, V> createChannelImpl(
String channelName,
Class<K> typeK, Class<V> typeV) {
- IEventChannel<K, V> castedEventChannel;
IEventChannel<?, ?> genericEventChannel =
eventChannels.get(channelName);
// Add the channel if the first listener
if (genericEventChannel == null) {
- castedEventChannel =
- new HazelcastEventChannel<K, V>(hazelcastInstance,
- channelName, typeK, typeV);
+ IEventChannel<K, V> castedEventChannel =
+ new HazelcastEventChannel<K, V>(hazelcastInstance,
+ channelName, typeK, typeV);
eventChannels.put(channelName, castedEventChannel);
- } else {
- //
- // TODO: Find if we can use Java internal support to check for
- // type mismatch.
- //
- if (!genericEventChannel.verifyKeyValueTypes(typeK, typeV)) {
- throw new ClassCastException("Key-value type mismatch for event channel " + channelName);
- }
- castedEventChannel = (IEventChannel<K, V>) genericEventChannel;
+ return castedEventChannel;
}
+ //
+ // TODO: Find if we can use Java internal support to check for
+ // type mismatch.
+ //
+ if (!genericEventChannel.verifyKeyValueTypes(typeK, typeV)) {
+ throw new ClassCastException("Key-value type mismatch for event channel " + channelName);
+ }
+ @SuppressWarnings("unchecked")
+ IEventChannel<K, V> castedEventChannel =
+ (IEventChannel<K, V>) genericEventChannel;
return castedEventChannel;
}
@@ -276,6 +277,7 @@
// NOTE: Using "ClassCastException" exception below doesn't
// work.
//
+ @SuppressWarnings("unchecked")
IEventChannel<K, V> castedEventChannel =
(IEventChannel<K, V>) genericEventChannel;
castedEventChannel.removeListener(listener);
diff --git a/src/main/java/net/onrc/onos/datagrid/HazelcastEventChannel.java b/src/main/java/net/onrc/onos/datagrid/HazelcastEventChannel.java
index 4d4bf9a..53d35c2 100644
--- a/src/main/java/net/onrc/onos/datagrid/HazelcastEventChannel.java
+++ b/src/main/java/net/onrc/onos/datagrid/HazelcastEventChannel.java
@@ -25,15 +25,15 @@
public class HazelcastEventChannel<K, V> implements IEventChannel<K, V> {
private final HazelcastInstance hazelcastInstance; // The Hazelcast instance
private final String channelName; // The event channel name
- private final Class<?> typeK; // The class type of the key
- private final Class<?> typeV; // The class type of the value
+ private final Class<K> typeK; // The class type of the key
+ private final Class<V> typeV; // The class type of the value
private IMap<K, byte[]> channelMap; // The Hazelcast channel map
// The channel listeners
private final CopyOnWriteArrayList<IEventChannelListener<K, V>> listeners =
new CopyOnWriteArrayList<>();
// The map entry listener
- private final MapEntryListener mapEntryListener = new MapEntryListener<K>();
+ private final EntryListener<K, byte[]> mapEntryListener = new MapEntryListener();
private String mapListenerId; // The map listener ID
// TODO: We should use a single global KryoFactory instance
@@ -295,7 +295,7 @@
* - Key: Type K
* - Value: Serialized V (byte[])
*/
- private class MapEntryListener<K> implements EntryListener<K, byte[]> {
+ private class MapEntryListener implements EntryListener<K, byte[]> {
/**
* Receive a notification that an entry is added.
*
@@ -315,7 +315,7 @@
// Deliver the notification
//
int index = 0;
- for (IEventChannelListener listener : listeners) {
+ for (IEventChannelListener<K, V> listener : listeners) {
V copyValue = value;
if (index++ > 0) {
// Each listener should get a deep copy of the value
@@ -345,7 +345,7 @@
// Deliver the notification
//
int index = 0;
- for (IEventChannelListener listener : listeners) {
+ for (IEventChannelListener<K, V> listener : listeners) {
V copyValue = value;
if (index++ > 0) {
// Each listener should get a deep copy of the value
@@ -375,7 +375,7 @@
// Deliver the notification
//
int index = 0;
- for (IEventChannelListener listener : listeners) {
+ for (IEventChannelListener<K, V> listener : listeners) {
V copyValue = value;
if (index++ > 0) {
// Each listener should get a deep copy of the value