diff --git a/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/context/TransportContext.java b/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/context/TransportContext.java index 5809378b6e..bae326b983 100644 --- a/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/context/TransportContext.java +++ b/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/context/TransportContext.java @@ -43,9 +43,12 @@ public final class TransportContext { private final RedirectionTransport redirectionTransport; private final LogTransport logTransport; - public TransportContext(MetaDataTransport mdTransport, BootstrapTransport bootstrapTransport, ProfileTransport profileTransport, - EventTransport eventTransport, NotificationTransport notificationTransport, ConfigurationTransport configurationTransport, - UserTransport userTransport, RedirectionTransport redirectionTransport, LogTransport logTransport) { + public TransportContext(MetaDataTransport mdTransport, BootstrapTransport bootstrapTransport, + ProfileTransport profileTransport, EventTransport eventTransport, + NotificationTransport notificationTransport, + ConfigurationTransport configurationTransport, + UserTransport userTransport, RedirectionTransport redirectionTransport, + LogTransport logTransport) { super(); this.mdTransport = mdTransport; this.bootstrapTransport = bootstrapTransport; diff --git a/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/package-info.java b/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/package-info.java index 26d5354e96..dcdab17d64 100644 --- a/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/package-info.java +++ b/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/package-info.java @@ -35,4 +35,5 @@ * @see org.kaaproject.kaa.client.Kaa * @see org.kaaproject.kaa.client.KaaClient */ + package org.kaaproject.kaa.client; \ No newline at end of file diff --git a/common/endpoint-shared/src/main/java/org/kaaproject/kaa/schema/base/Notification.java b/common/endpoint-shared/src/main/java/org/kaaproject/kaa/schema/base/Notification.java index 2980d17415..2858dcb307 100644 --- a/common/endpoint-shared/src/main/java/org/kaaproject/kaa/schema/base/Notification.java +++ b/common/endpoint-shared/src/main/java/org/kaaproject/kaa/schema/base/Notification.java @@ -89,8 +89,8 @@ public Notification build() { try { Notification record = new Notification(); return record; - } catch (Exception e) { - throw new org.apache.avro.AvroRuntimeException(e); + } catch (Exception exception) { + throw new org.apache.avro.AvroRuntimeException(exception); } } } diff --git a/server/common/netty-server/src/main/java/org/kaaproject/kaa/server/common/server/AbstractNettyServer.java b/server/common/netty-server/src/main/java/org/kaaproject/kaa/server/common/server/AbstractNettyServer.java index 724817ec69..70274727fc 100644 --- a/server/common/netty-server/src/main/java/org/kaaproject/kaa/server/common/server/AbstractNettyServer.java +++ b/server/common/netty-server/src/main/java/org/kaaproject/kaa/server/common/server/AbstractNettyServer.java @@ -51,13 +51,14 @@ public abstract class AbstractNettyServer extends Thread { private final int bindPort; private EventLoopGroup bossGroup; private EventLoopGroup workerGroup; - private ServerBootstrap bServer; + private ServerBootstrap btsServer; private Channel bindChannel; /** * NettyHttpServer constructor. * - * @param conf Config + * @param bindAddress bind address + * @param port bind port */ public AbstractNettyServer(String bindAddress, int port) { this.bindAddress = bindAddress; @@ -77,18 +78,20 @@ public void init() { LOG.debug("NettyServer bossGroup created"); workerGroup = new NioEventLoopGroup(); LOG.debug("NettyServer workGroup created"); - bServer = new ServerBootstrap(); + btsServer = new ServerBootstrap(); LOG.debug("NettyServer ServerBootstrap created"); - ChannelInitializer sInit = configureInitializer(); + ChannelInitializer serverInit = configureInitializer(); LOG.debug("NettyServer InitClass instance created"); LOG.debug("NettyServer InitClass instance init()"); - bServer.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(sInit) + btsServer.group(bossGroup, workerGroup) + .channel(NioServerSocketChannel.class) + .childHandler(serverInit) .option(ChannelOption.SO_REUSEADDR, true); LOG.debug("NettyServer ServerBootstrap group initialized"); - bindChannel = bServer.bind(bindAddress, bindPort).sync().channel(); - } catch (Exception e) { - LOG.error("NettyHttpServer init() failed", e); + bindChannel = btsServer.bind(bindAddress, bindPort).sync().channel(); + } catch (Exception exception) { + LOG.error("NettyHttpServer init() failed", exception); } } @@ -97,8 +100,8 @@ public void run() { LOG.info("NettyHttpServer starting..."); try { bindChannel.closeFuture().sync(); - } catch (InterruptedException e) { - LOG.error("NettyHttpServer error", e); + } catch (InterruptedException exption) { + LOG.error("NettyHttpServer error", exption); } finally { shutdown(); LOG.info("NettyHttpServer shut down"); @@ -112,10 +115,11 @@ public void shutdown() { LOG.info("NettyHttpServer stopping..."); if (bossGroup != null) { try { - Future f = bossGroup.shutdownGracefully(250, 1000, TimeUnit.MILLISECONDS); - f.await(); - } catch (InterruptedException e) { - LOG.trace("NettyHttpServer stopping: bossGroup error", e); + Future future = bossGroup.shutdownGracefully( + 250, 1000, TimeUnit.MILLISECONDS); + future.await(); + } catch (InterruptedException exception) { + LOG.trace("NettyHttpServer stopping: bossGroup error", exception); } finally { bossGroup = null; LOG.trace("NettyHttpServer stopping: bossGroup stoped"); @@ -123,10 +127,11 @@ public void shutdown() { } if (workerGroup != null) { try { - Future f = workerGroup.shutdownGracefully(250, 1000, TimeUnit.MILLISECONDS); - f.await(); - } catch (InterruptedException e) { - LOG.trace("NettyHttpServer stopping: workerGroup error", e); + Future future = workerGroup.shutdownGracefully( + 250, 1000, TimeUnit.MILLISECONDS); + future.await(); + } catch (InterruptedException exception) { + LOG.trace("NettyHttpServer stopping: workerGroup error", exception); } finally { workerGroup = null; LOG.trace("NettyHttpServer stopping: workerGroup stopped"); diff --git a/server/common/netty-server/src/main/java/org/kaaproject/kaa/server/common/server/CommandFactory.java b/server/common/netty-server/src/main/java/org/kaaproject/kaa/server/common/server/CommandFactory.java index 76e1827dd5..758a1ad680 100644 --- a/server/common/netty-server/src/main/java/org/kaaproject/kaa/server/common/server/CommandFactory.java +++ b/server/common/netty-server/src/main/java/org/kaaproject/kaa/server/common/server/CommandFactory.java @@ -43,7 +43,7 @@ public CommandFactory(List> factories) { /** * getCommandProcessor - used to instantiate CommandProcessor for specific - * URI + * URI. * * @param uri - HTTP request URI, should have following format: /DOMAIN/CommandName * @return - CommandProcessor diff --git a/server/common/netty-server/src/main/java/org/kaaproject/kaa/server/common/server/NettyChannelContext.java b/server/common/netty-server/src/main/java/org/kaaproject/kaa/server/common/server/NettyChannelContext.java index 1f290fcf51..eb1e2cecab 100644 --- a/server/common/netty-server/src/main/java/org/kaaproject/kaa/server/common/server/NettyChannelContext.java +++ b/server/common/netty-server/src/main/java/org/kaaproject/kaa/server/common/server/NettyChannelContext.java @@ -39,8 +39,8 @@ public void writeAndFlush(Object msg) { } @Override - public void fireExceptionCaught(Exception e) { - ctx.fireExceptionCaught(e); + public void fireExceptionCaught(Exception exception) { + ctx.fireExceptionCaught(exception); } @Override diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/AbstractVersionableCassandraDao.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/AbstractVersionableCassandraDao.java index 00ace0f159..c0b32408ce 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/AbstractVersionableCassandraDao.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/AbstractVersionableCassandraDao.java @@ -38,13 +38,14 @@ import java.util.List; -public abstract class AbstractVersionableCassandraDao extends AbstractCassandraDao { +public abstract class AbstractVersionableCassandraDao + extends AbstractCassandraDao { private static final Logger LOG = LoggerFactory.getLogger(AbstractVersionableCassandraDao.class); public T save(T entity) { if (entity.getVersion() == null) { - entity.setVersion(0l); + entity.setVersion(0L); LOG.debug("Save entity {}", entity); return insertLocked(entity); } else { @@ -58,18 +59,23 @@ private Clause[] buildKeyClauses(CassandraEntityMapper entityMapper, T entity Clause[] clauses = new Clause[keyColumns.size()]; for (int i = 0; i < keyColumns.size(); i++) { String columnName = keyColumns.get(i); - clauses[i] = eq(columnName, entityMapper.getColumnValueForName(columnName, entity, cassandraClient)); + clauses[i] = eq( + columnName, entityMapper.getColumnValueForName(columnName, entity, cassandraClient)); } return clauses; } private T updateLocked(T entity) { - long version = (entity.getVersion() == null) ? 0l : entity.getVersion(); - Assignments assigns = update(getColumnFamilyName()).onlyIf(eq(OPT_LOCK, version)).with(set(OPT_LOCK, version + 1)); - CassandraEntityMapper entityMapper = CassandraEntityMapper.getEntityMapperForClass(getColumnFamilyClass(), cassandraClient); + long version = (entity.getVersion() == null) ? 0L : entity.getVersion(); + Assignments assigns = update(getColumnFamilyName()) + .onlyIf(eq(OPT_LOCK, version)) + .with(set(OPT_LOCK, version + 1)); + CassandraEntityMapper entityMapper = CassandraEntityMapper.getEntityMapperForClass( + getColumnFamilyClass(), cassandraClient); for (String name : entityMapper.getNonKeyColumnNames()) { if (!name.equals(OPT_LOCK)) { - Assignment assignment = set(name, entityMapper.getColumnValueForName(name, entity, cassandraClient)); + Assignment assignment = set( + name, entityMapper.getColumnValueForName(name, entity, cassandraClient)); assigns = assigns.and(assignment); } } @@ -83,8 +89,10 @@ private T updateLocked(T entity) { query.setConsistencyLevel(getWriteConsistencyLevel()); ResultSet res = execute(query); if (!res.wasApplied()) { - LOG.error("[{}] Can't update entity with version {}. Entity already changed!", getColumnFamilyClass(), version); - throw new KaaOptimisticLockingFailureException("Can't update entity with version " + version + ". Entity already changed!"); + LOG.error("[{}] Can't update entity with version {}. Entity already changed!", + getColumnFamilyClass(), version); + throw new KaaOptimisticLockingFailureException("Can't update entity with version " + + version + ". Entity already changed!"); } else { Select.Where where = select().from(getColumnFamilyName()).where(whereClauses[0]); if (whereClauses.length > 1) { @@ -98,7 +106,8 @@ private T updateLocked(T entity) { private T insertLocked(T entity) { Insert insert = insertInto(getColumnFamilyName()).ifNotExists(); - CassandraEntityMapper entityMapper = CassandraEntityMapper.getEntityMapperForClass(getColumnFamilyClass(), cassandraClient); + CassandraEntityMapper entityMapper = CassandraEntityMapper.getEntityMapperForClass( + getColumnFamilyClass(), cassandraClient); for (String name : entityMapper.getKeyColumnNames()) { insert.value(name, entityMapper.getColumnValueForName(name, entity, cassandraClient)); } diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/CredentialsCassandraDao.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/CredentialsCassandraDao.java index 3f12313b1c..8e3687c657 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/CredentialsCassandraDao.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/CredentialsCassandraDao.java @@ -42,7 +42,9 @@ import java.util.Optional; @Repository -public class CredentialsCassandraDao extends AbstractCassandraDao implements CredentialsDao { +public class CredentialsCassandraDao + extends AbstractCassandraDao + implements CredentialsDao { private static final Logger LOG = LoggerFactory.getLogger(CredentialsCassandraDao.class); @@ -64,7 +66,8 @@ public CassandraCredentials save(String applicationId, CredentialsDto credential @Override public Optional find(String applicationId, String credentialsId) { - LOG.debug("Searching credential by applicationID[{}] and credentialsID[{}]", applicationId, credentialsId); + LOG.debug("Searching credential by applicationID[{}] and credentialsID[{}]", + applicationId, credentialsId); Select.Where query = select().from(getColumnFamilyName()). where(eq(CREDENTIALS_APPLICATION_ID_PROPERTY, applicationId)). and(eq(CREDENTIALS_ID_PROPERTY, credentialsId)); @@ -72,10 +75,14 @@ public Optional find(String applicationId, String credenti } @Override - public Optional updateStatus(String applicationId, String credentialsId, CredentialsStatus status) { - LOG.debug("Updating credentials status with applicationID[{}] and credentialsID[{}] to STATUS[{}]", + public Optional updateStatus(String applicationId, + String credentialsId, + CredentialsStatus status) { + LOG.debug("Updating credentials status with applicationID[{}] " + + "and credentialsID[{}] to STATUS[{}]", applicationId, credentialsId, status.toString()); - Update.Assignments query = update(getColumnFamilyName()).where(eq(CREDENTIALS_ID_PROPERTY, credentialsId)). + Update.Assignments query = update(getColumnFamilyName()) + .where(eq(CREDENTIALS_ID_PROPERTY, credentialsId)). and(eq(CREDENTIALS_APPLICATION_ID_PROPERTY, applicationId)). with(set(CREDENTIALS_STATUS_PROPERTY, status.toString())); execute(query); @@ -84,7 +91,8 @@ public Optional updateStatus(String applicationId, String @Override public void remove(String applicationId, String credentialsId) { - LOG.debug("Deleting credential by applicationID[{}] and credentialsID[{}]", applicationId, credentialsId); + LOG.debug("Deleting credential by applicationID[{}] and credentialsID[{}]", + applicationId, credentialsId); Delete.Where query = delete().from(getColumnFamilyName()). where(eq(CREDENTIALS_ID_PROPERTY, credentialsId)). and(eq(CREDENTIALS_APPLICATION_ID_PROPERTY, applicationId)); diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/EndpointConfigurationCassandraDao.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/EndpointConfigurationCassandraDao.java index f117ef6c2e..543184c8fd 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/EndpointConfigurationCassandraDao.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/EndpointConfigurationCassandraDao.java @@ -30,10 +30,12 @@ import java.nio.ByteBuffer; @Repository(value = "endpointConfigurationDao") -public class EndpointConfigurationCassandraDao extends AbstractCassandraDao +public class EndpointConfigurationCassandraDao + extends AbstractCassandraDao implements EndpointConfigurationDao { - private static final Logger LOG = LoggerFactory.getLogger(EndpointConfigurationCassandraDao.class); + private static final Logger LOG = + LoggerFactory.getLogger(EndpointConfigurationCassandraDao.class); @Override protected Class getColumnFamilyClass() { diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/EndpointProfileCassandraDao.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/EndpointProfileCassandraDao.java index 12b4393478..bca0d1f0fe 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/EndpointProfileCassandraDao.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/EndpointProfileCassandraDao.java @@ -37,9 +37,9 @@ import org.kaaproject.kaa.server.common.nosql.cassandra.dao.filter.CassandraEpbyAppIdDao; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.filter.CassandraEpByEndpointGroupIdDao; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.filter.CassandraEpBySdkTokenDao; -import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEPByAccessToken; -import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEPByAppId; -import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEPByEndpointGroupId; +import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEpByAccessToken; +import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEpByAppId; +import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEpByEndpointGroupId; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEpBySdkToken; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEndpointProfile; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEndpointUser; @@ -135,12 +135,12 @@ private CassandraEndpointProfile saveProfile(CassandraEndpointProfile profile) { ByteBuffer epKeyHash = profile.getEndpointKeyHash(); List statementList = new ArrayList<>(); statementList.add(cassandraEpByAppIdDao.getSaveQuery( - new CassandraEPByAppId(profile.getApplicationId(), epKeyHash))); + new CassandraEpByAppId(profile.getApplicationId(), epKeyHash))); String accessToken = profile.getAccessToken(); if (accessToken != null) { statementList.add( cassandraEpByAccessTokenDao.getSaveQuery( - new CassandraEPByAccessToken(accessToken, epKeyHash))); + new CassandraEpByAccessToken(accessToken, epKeyHash))); } statementList.add(getSaveQuery(profile)); Statement saveBySdkTokenId = cassandraEpBySdkTokenDao.getSaveQuery( @@ -150,7 +150,7 @@ private CassandraEndpointProfile saveProfile(CassandraEndpointProfile profile) { for (String groupId : groupIdSet) { statementList.add( cassandraEpByEndpointGroupIdDao.getSaveQuery( - new CassandraEPByEndpointGroupId(groupId, epKeyHash))); + new CassandraEpByEndpointGroupId(groupId, epKeyHash))); } executeBatch(statementList.toArray(new Statement[statementList.size()])); LOG.debug("[{}] Endpoint profile saved", profile.getId()); @@ -177,7 +177,7 @@ private CassandraEndpointProfile updateProfile(CassandraEndpointProfile profile) if (addEndpointGroupIds != null) { for (String id : addEndpointGroupIds) { statementList.add(cassandraEpByEndpointGroupIdDao.getSaveQuery( - new CassandraEPByEndpointGroupId(id, epKeyHash))); + new CassandraEpByEndpointGroupId(id, epKeyHash))); } if (removeEndpointGroupIds != null) { @@ -205,7 +205,7 @@ private CassandraEndpointProfile updateProfile(CassandraEndpointProfile profile) } if (accessToken != null) { statementList.add(cassandraEpByAccessTokenDao.getSaveQuery( - new CassandraEPByAccessToken(accessToken, epKeyHash))); + new CassandraEpByAccessToken(accessToken, epKeyHash))); } executeBatch(statementList.toArray(new Statement[statementList.size()])); LOG.debug("[{}] Endpoint profile updated", profile.getId()); diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/NotificationCassandraDao.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/NotificationCassandraDao.java index 99fb0e0d37..83bac11ea9 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/NotificationCassandraDao.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/NotificationCassandraDao.java @@ -43,7 +43,9 @@ import com.datastax.driver.core.querybuilder.Select.Where; @Repository -public class NotificationCassandraDao extends AbstractCassandraDao implements NotificationDao { +public class NotificationCassandraDao + extends AbstractCassandraDao + implements NotificationDao { private static final Logger LOG = LoggerFactory.getLogger(NotificationCassandraDao.class); @@ -61,10 +63,11 @@ protected String getColumnFamilyName() { public CassandraNotification findById(String id) { LOG.debug("Try to find notification by id {}", id); CassandraNotification nf = new CassandraNotification(id); - Where query = select().from(getColumnFamilyName()).where(eq(NF_TOPIC_ID_PROPERTY, nf.getTopicId())) - .and(eq(NF_NOTIFICATION_TYPE_PROPERTY, nf.getType().name())) - .and(eq(NF_VERSION_PROPERTY, nf.getNfVersion())) - .and(eq(NF_SEQ_NUM_PROPERTY, nf.getSeqNum())); + Where query = select().from(getColumnFamilyName()) + .where(eq(NF_TOPIC_ID_PROPERTY, nf.getTopicId())) + .and(eq(NF_NOTIFICATION_TYPE_PROPERTY, nf.getType().name())) + .and(eq(NF_VERSION_PROPERTY, nf.getNfVersion())) + .and(eq(NF_SEQ_NUM_PROPERTY, nf.getSeqNum())); LOG.trace("Execute query {}", query); nf = findOneByStatement(query); LOG.trace("Found notification {} by id {}", nf, id); @@ -75,10 +78,11 @@ public CassandraNotification findById(String id) { public void removeById(String id) { LOG.debug("Remove notification by id {}", id); CassandraNotification nf = new CassandraNotification(id); - Delete.Where deleteQuery = delete().from(getColumnFamilyName()).where(eq(NF_TOPIC_ID_PROPERTY, nf.getTopicId())) - .and(eq(NF_NOTIFICATION_TYPE_PROPERTY, nf.getType().name())) - .and(eq(NF_VERSION_PROPERTY, nf.getNfVersion())) - .and(eq(NF_SEQ_NUM_PROPERTY, nf.getSeqNum())); + Delete.Where deleteQuery = delete().from(getColumnFamilyName()) + .where(eq(NF_TOPIC_ID_PROPERTY, nf.getTopicId())) + .and(eq(NF_NOTIFICATION_TYPE_PROPERTY, nf.getType().name())) + .and(eq(NF_VERSION_PROPERTY, nf.getNfVersion())) + .and(eq(NF_SEQ_NUM_PROPERTY, nf.getSeqNum())); LOG.trace("Remove notification by id {}", deleteQuery); execute(deleteQuery); } @@ -101,7 +105,8 @@ public CassandraNotification save(NotificationDto notification) { public List findNotificationsByTopicId(String topicId) { LOG.debug("Try to find notifications by topic id {}", topicId); Where query = select().from(getColumnFamilyName()).where(eq(NF_TOPIC_ID_PROPERTY, topicId)) - .and(QueryBuilder.in(NF_NOTIFICATION_TYPE_PROPERTY, getStringTypes(NotificationTypeDto.values()))); + .and(QueryBuilder.in( + NF_NOTIFICATION_TYPE_PROPERTY, getStringTypes(NotificationTypeDto.values()))); LOG.trace("Execute query {}", query); List notifications = findListByStatement(query); if (LOG.isTraceEnabled()) { @@ -113,31 +118,41 @@ public List findNotificationsByTopicId(String topicId) { @Override public void removeNotificationsByTopicId(String topicId) { LOG.debug("Remove notifications by topic id {}", topicId); - Delete.Where query = delete().from(getColumnFamilyName()).where(eq(NF_TOPIC_ID_PROPERTY, topicId)) - .and(QueryBuilder.in(NF_NOTIFICATION_TYPE_PROPERTY, getStringTypes(NotificationTypeDto.values()))); + Delete.Where query = delete().from(getColumnFamilyName()) + .where(eq(NF_TOPIC_ID_PROPERTY, topicId)) + .and(QueryBuilder.in( + NF_NOTIFICATION_TYPE_PROPERTY, getStringTypes(NotificationTypeDto.values()))); execute(query); LOG.trace("Execute query {}", query); } @Override - public List findNotificationsByTopicIdAndVersionAndStartSecNum(String topicId, int seqNum, int sysNfVersion, int userNfVersion) { - LOG.debug("Try to find notifications by topic id {} start sequence number {} system schema version {} user schema version {}", topicId, seqNum, sysNfVersion, userNfVersion); + public List findNotificationsByTopicIdAndVersionAndStartSecNum(String topicId, + int seqNum, + int sysNfVersion, + int userNfVersion) { + LOG.debug("Try to find notifications by topic id {} start sequence number {} " + + "system schema version {} user schema version {}", + topicId, seqNum, sysNfVersion, userNfVersion); List resultList = new ArrayList<>(); - Where systemQuery = select().from(getColumnFamilyName()).where(eq(NF_TOPIC_ID_PROPERTY, topicId)) + Where systemQuery = select().from(getColumnFamilyName()) + .where(eq(NF_TOPIC_ID_PROPERTY, topicId)) .and(eq(NF_NOTIFICATION_TYPE_PROPERTY, NotificationTypeDto.SYSTEM.name())) .and(eq(NF_VERSION_PROPERTY, sysNfVersion)) .and(QueryBuilder.gt(NF_SEQ_NUM_PROPERTY, seqNum)); - Where userQuery = select().from(getColumnFamilyName()).where(eq(NF_TOPIC_ID_PROPERTY, topicId)) - .and(eq(NF_NOTIFICATION_TYPE_PROPERTY, NotificationTypeDto.USER.name())) - .and(eq(NF_VERSION_PROPERTY, userNfVersion)) - .and(QueryBuilder.gt(NF_SEQ_NUM_PROPERTY, seqNum)); + Where userQuery = select().from(getColumnFamilyName()) + .where(eq(NF_TOPIC_ID_PROPERTY, topicId)) + .and(eq(NF_NOTIFICATION_TYPE_PROPERTY, NotificationTypeDto.USER.name())) + .and(eq(NF_VERSION_PROPERTY, userNfVersion)) + .and(QueryBuilder.gt(NF_SEQ_NUM_PROPERTY, seqNum)); List systemList = findListByStatement(systemQuery); List userList = findListByStatement(userQuery); resultList.addAll(systemList); resultList.addAll(userList); if (LOG.isTraceEnabled()) { LOG.trace("Found notifications {} by topic id {}, seqNum {}, sysVer {}, userVer {} ", - Arrays.toString(resultList.toArray()), topicId, seqNum, sysNfVersion, userNfVersion); + Arrays.toString( + resultList.toArray()), topicId, seqNum, sysNfVersion, userNfVersion); } return resultList; } diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/filter/CassandraEpByAccessTokenDao.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/filter/CassandraEpByAccessTokenDao.java index e76335b147..a9b4d10f50 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/filter/CassandraEpByAccessTokenDao.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/filter/CassandraEpByAccessTokenDao.java @@ -19,7 +19,7 @@ import java.nio.ByteBuffer; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.AbstractCassandraDao; -import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEPByAccessToken; +import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEpByAccessToken; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,12 +27,12 @@ @Repository public class CassandraEpByAccessTokenDao - extends AbstractCassandraDao { + extends AbstractCassandraDao { private static final Logger LOG = LoggerFactory.getLogger(CassandraEpByAccessTokenDao.class); @Override - protected Class getColumnFamilyClass() { - return CassandraEPByAccessToken.class; + protected Class getColumnFamilyClass() { + return CassandraEpByAccessToken.class; } @Override @@ -43,7 +43,7 @@ protected String getColumnFamilyName() { public ByteBuffer findEpIdByAccessToken(String accessToken) { LOG.debug("Try to find endpoint key hash by access token {}", accessToken); ByteBuffer endpointKeyHash = null; - CassandraEPByAccessToken result = findById(accessToken); + CassandraEpByAccessToken result = findById(accessToken); if (result != null) { endpointKeyHash = result.getEndpointKeyHash(); } diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/filter/CassandraEpByEndpointGroupIdDao.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/filter/CassandraEpByEndpointGroupIdDao.java index 342b7244af..1fd347f7c9 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/filter/CassandraEpByEndpointGroupIdDao.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/filter/CassandraEpByEndpointGroupIdDao.java @@ -29,7 +29,7 @@ import org.apache.commons.codec.binary.Base64; import org.kaaproject.kaa.common.dto.PageLinkDto; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.AbstractCassandraDao; -import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEPByEndpointGroupId; +import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEpByEndpointGroupId; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,14 +39,14 @@ @Repository public class CassandraEpByEndpointGroupIdDao - extends AbstractCassandraDao { + extends AbstractCassandraDao { private static final Logger LOG = LoggerFactory.getLogger(CassandraEpByEndpointGroupIdDao.class); @Override - protected Class getColumnFamilyClass() { - return CassandraEPByEndpointGroupId.class; + protected Class getColumnFamilyClass() { + return CassandraEpByEndpointGroupId.class; } @Override @@ -54,10 +54,10 @@ protected String getColumnFamilyName() { return CassandraModelConstants.EP_BY_ENDPOINT_GROUP_ID_COLUMN_FAMILY_NAME; } - private ByteBuffer[] getEndpointKeyHash(List filter) { + private ByteBuffer[] getEndpointKeyHash(List filter) { ByteBuffer[] endpointKeyHash = new ByteBuffer[filter.size()]; int pos = 0; - for (CassandraEPByEndpointGroupId ep : filter) { + for (CassandraEpByEndpointGroupId ep : filter) { endpointKeyHash[pos++] = ep.getEndpointKeyHash(); } return endpointKeyHash; @@ -84,7 +84,7 @@ public ByteBuffer[] findEpByEndpointGroupId(PageLinkDto pageLink) { + "with limit {} start from keyHash {}", endpointGroupId, limit, endpointKey); } - List filter = findListByStatement(queryStatement); + List filter = findListByStatement(queryStatement); return getEndpointKeyHash(filter); } } diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/filter/CassandraEpbyAppIdDao.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/filter/CassandraEpbyAppIdDao.java index 46e8a2191c..d7413b03ce 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/filter/CassandraEpbyAppIdDao.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/filter/CassandraEpbyAppIdDao.java @@ -29,7 +29,7 @@ import org.apache.commons.codec.binary.Base64; import org.kaaproject.kaa.common.dto.PageLinkDto; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.AbstractCassandraDao; -import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEPByAppId; +import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEpByAppId; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,13 +38,13 @@ import com.datastax.driver.core.Statement; @Repository -public class CassandraEpbyAppIdDao extends AbstractCassandraDao { +public class CassandraEpbyAppIdDao extends AbstractCassandraDao { private static final Logger LOG = LoggerFactory.getLogger(CassandraEpbyAppIdDao.class); @Override - protected Class getColumnFamilyClass() { - return CassandraEPByAppId.class; + protected Class getColumnFamilyClass() { + return CassandraEpByAppId.class; } @Override @@ -54,21 +54,21 @@ protected String getColumnFamilyName() { public ByteBuffer[] getEpIdsListByAppId(String appId) { LOG.debug("Try to find endpoint key hash list by application id {}", appId); - List filter = findListByStatement(select() + List filter = findListByStatement(select() .from(getColumnFamilyName()) .where(eq(EP_BY_APP_ID_APPLICATION_ID_PROPERTY, appId))); ByteBuffer[] result = new ByteBuffer[filter.size()]; int pos = 0; - for (CassandraEPByAppId ep : filter) { + for (CassandraEpByAppId ep : filter) { result[pos++] = ep.getEndpointKeyHash(); } return result; } - private ByteBuffer[] getEndpointKeyHash(List filter) { + private ByteBuffer[] getEndpointKeyHash(List filter) { ByteBuffer[] endpointKeyHash = new ByteBuffer[filter.size()]; int pos = 0; - for (CassandraEPByAppId ep : filter) { + for (CassandraEpByAppId ep : filter) { endpointKeyHash[pos++] = ep.getEndpointKeyHash(); } return endpointKeyHash; @@ -94,7 +94,7 @@ public ByteBuffer[] findEpByAppId(PageLinkDto pageLink, String appId) { + "with limit {} start from keyHash {}", appId, limit, endpointKey); } - List filter = findListByStatement(queryStatement); + List filter = findListByStatement(queryStatement); return getEndpointKeyHash(filter); } } diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraCredentials.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraCredentials.java index 929bbeaf89..c3c47e4a52 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraCredentials.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraCredentials.java @@ -111,15 +111,28 @@ public void setCassandraCredentialsStatus(String cassandraCredentialsStatus) { } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + public boolean equals(Object object) { + if (this == object) { + return true; + } - CassandraCredentials that = (CassandraCredentials) o; + if (object == null || getClass() != object.getClass()) { + return false; + } - if (!applicationId.equals(that.applicationId)) return false; - if (!cassandraCredentialsStatus.equals(that.cassandraCredentialsStatus)) return false; - if (!cassandraCredentialsBody.equals(that.cassandraCredentialsBody)) return false; + CassandraCredentials that = (CassandraCredentials) object; + + if (!applicationId.equals(that.applicationId)) { + return false; + } + + if (!cassandraCredentialsStatus.equals(that.cassandraCredentialsStatus)) { + return false; + } + + if (!cassandraCredentialsBody.equals(that.cassandraCredentialsBody)) { + return false; + } return true; } @@ -134,12 +147,12 @@ public int hashCode() { @Override public String toString() { - return "CassandraCredentials{" + - "applicationId='" + applicationId + '\'' + - ", id='" + id + '\'' + - ", credentialsBody=" + cassandraCredentialsBody + - ", status='" + cassandraCredentialsStatus + '\'' + - '}'; + return "CassandraCredentials{" + + "applicationId='" + applicationId + '\'' + + ", id='" + id + '\'' + + ", credentialsBody=" + cassandraCredentialsBody + + ", status='" + cassandraCredentialsStatus + '\'' + + '}'; } @Override diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEndpointConfiguration.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEndpointConfiguration.java index 9767d2ebd9..581cebecc2 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEndpointConfiguration.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEndpointConfiguration.java @@ -82,22 +82,27 @@ public void setId(String id) { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - CassandraEndpointConfiguration that = (CassandraEndpointConfiguration) o; + CassandraEndpointConfiguration that = (CassandraEndpointConfiguration) object; - if (configuration != null ? !configuration.equals(that.configuration) : that.configuration != null) { + if (configuration != null + ? !configuration.equals(that.configuration) + : that.configuration != null) { return false; } - if (configurationHash != null ? !configurationHash.equals(that.configurationHash) : that.configurationHash != null) { + if (configurationHash != null + ? !configurationHash.equals(that.configurationHash) + : that.configurationHash != null) { return false; } + if (id != null ? !id.equals(that.id) : that.id != null) { return false; } @@ -115,10 +120,10 @@ public int hashCode() { @Override public String toString() { - return "EndpointConfiguration{" + - "configurationHash=" + configurationHash + - ", configuration=" + configuration + - '}'; + return "EndpointConfiguration{" + + "configurationHash=" + configurationHash + + ", configuration=" + configuration + + '}'; } @Override diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEPByAccessToken.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEpByAccessToken.java similarity index 81% rename from server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEPByAccessToken.java rename to server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEpByAccessToken.java index e0024149d5..cddd68efcc 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEPByAccessToken.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEpByAccessToken.java @@ -25,7 +25,7 @@ import java.nio.ByteBuffer; @Table(name = CassandraModelConstants.EP_BY_ACCESS_TOKEN_COLUMN_FAMILY_NAME) -public class CassandraEPByAccessToken implements Serializable { +public class CassandraEpByAccessToken implements Serializable { @Transient private static final long serialVersionUID = -8826203709978813176L; @@ -36,10 +36,10 @@ public class CassandraEPByAccessToken implements Serializable { @Column(name = CassandraModelConstants.EP_BY_ACCESS_TOKEN_ENDPOINT_KEY_HASH_PROPERTY) private ByteBuffer endpointKeyHash; - public CassandraEPByAccessToken() { + public CassandraEpByAccessToken() { } - public CassandraEPByAccessToken(String accessToken, ByteBuffer endpointKeyHash) { + public CassandraEpByAccessToken(String accessToken, ByteBuffer endpointKeyHash) { this.accessToken = accessToken; this.endpointKeyHash = endpointKeyHash; } @@ -61,20 +61,23 @@ public void setEndpointKeyHash(ByteBuffer endpointKeyHash) { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - CassandraEPByAccessToken that = (CassandraEPByAccessToken) o; + CassandraEpByAccessToken that = (CassandraEpByAccessToken) object; if (accessToken != null ? !accessToken.equals(that.accessToken) : that.accessToken != null) { return false; } - if (endpointKeyHash != null ? !endpointKeyHash.equals(that.endpointKeyHash) : that.endpointKeyHash != null) { + + if (endpointKeyHash != null + ? !endpointKeyHash.equals(that.endpointKeyHash) + : that.endpointKeyHash != null) { return false; } @@ -90,7 +93,7 @@ public int hashCode() { @Override public String toString() { - return "CassandraEPByAccessToken{" + + return "CassandraEpByAccessToken{" + "accessToken='" + accessToken + '\'' + ", endpointKeyHash=" + endpointKeyHash + '}'; diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEPByAppId.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEpByAppId.java similarity index 79% rename from server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEPByAppId.java rename to server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEpByAppId.java index 216975f985..0c2860dbe5 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEPByAppId.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEpByAppId.java @@ -26,7 +26,7 @@ import java.nio.ByteBuffer; @Table(name = CassandraModelConstants.EP_BY_APP_ID_COLUMN_FAMILY_NAME) -public class CassandraEPByAppId implements Serializable { +public class CassandraEpByAppId implements Serializable { @Transient private static final long serialVersionUID = 4620788066149588088L; @@ -38,10 +38,10 @@ public class CassandraEPByAppId implements Serializable { @Column(name = CassandraModelConstants.EP_BY_APP_ID_ENDPOINT_KEY_HASH_PROPERTY) private ByteBuffer endpointKeyHash; - public CassandraEPByAppId() { + public CassandraEpByAppId() { } - public CassandraEPByAppId(String appId, ByteBuffer endpointKeyHash) { + public CassandraEpByAppId(String appId, ByteBuffer endpointKeyHash) { this.appId = appId; this.endpointKeyHash = endpointKeyHash; } @@ -63,20 +63,23 @@ public void setEndpointKeyHash(ByteBuffer endpointKeyHash) { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - CassandraEPByAppId that = (CassandraEPByAppId) o; + CassandraEpByAppId that = (CassandraEpByAppId) object; if (appId != null ? !appId.equals(that.appId) : that.appId != null) { return false; } - if (endpointKeyHash != null ? !endpointKeyHash.equals(that.endpointKeyHash) : that.endpointKeyHash != null) { + + if (endpointKeyHash != null + ? !endpointKeyHash.equals(that.endpointKeyHash) + : that.endpointKeyHash != null) { return false; } @@ -92,9 +95,9 @@ public int hashCode() { @Override public String toString() { - return "CassandraEPByAppId{" + - "appId='" + appId + '\'' + - ", endpointKeyHash=" + endpointKeyHash + - '}'; + return "CassandraEpByAppId{" + + "appId='" + appId + '\'' + + ", endpointKeyHash=" + endpointKeyHash + + '}'; } } diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEPByEndpointGroupId.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEpByEndpointGroupId.java similarity index 88% rename from server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEPByEndpointGroupId.java rename to server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEpByEndpointGroupId.java index 2f577db0c4..f49077f6e9 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEPByEndpointGroupId.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEpByEndpointGroupId.java @@ -26,7 +26,7 @@ import java.nio.ByteBuffer; @Table(name = CassandraModelConstants.EP_BY_ENDPOINT_GROUP_ID_COLUMN_FAMILY_NAME) -public class CassandraEPByEndpointGroupId implements Serializable { +public class CassandraEpByEndpointGroupId implements Serializable { @Transient private static final long serialVersionUID = 4892433114353644609L; @@ -38,10 +38,10 @@ public class CassandraEPByEndpointGroupId implements Serializable { @Column(name = CassandraModelConstants.EP_BY_ENDPOINT_GROUP_ID_ENDPOINT_KEY_HASH_PROPERTY) private ByteBuffer endpointKeyHash; - public CassandraEPByEndpointGroupId() { + public CassandraEpByEndpointGroupId() { } - public CassandraEPByEndpointGroupId(String epGroupId, ByteBuffer endpointKeyHash) { + public CassandraEpByEndpointGroupId(String epGroupId, ByteBuffer endpointKeyHash) { this.epGroupId = epGroupId; this.endpointKeyHash = endpointKeyHash; } @@ -82,7 +82,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - CassandraEPByEndpointGroupId other = (CassandraEPByEndpointGroupId) obj; + CassandraEpByEndpointGroupId other = (CassandraEpByEndpointGroupId) obj; if (endpointKeyHash == null) { if (other.endpointKeyHash != null) { return false; @@ -102,9 +102,9 @@ public boolean equals(Object obj) { @Override public String toString() { - return "CassandraEPByAccessToken{" + - "epGroupId='" + epGroupId + '\'' + - ", endpointKeyHash=" + endpointKeyHash + - '}'; + return "CassandraEpByAccessToken{" + + "epGroupId='" + epGroupId + '\'' + + ", endpointKeyHash=" + endpointKeyHash + + '}'; } } diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEpRegistrationByEndpointId.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEpRegistrationByEndpointId.java index 232c63f5c9..301dc0b724 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEpRegistrationByEndpointId.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEpRegistrationByEndpointId.java @@ -48,7 +48,8 @@ public final class CassandraEpRegistrationByEndpointId implements Serializable { private String credentialsId; - public static CassandraEpRegistrationByEndpointId fromEndpointRegistration(EndpointRegistration endpointRegistration) { + public static CassandraEpRegistrationByEndpointId fromEndpointRegistration( + EndpointRegistration endpointRegistration) { String endpointId = endpointRegistration.getEndpointId(); String credentialsId = endpointRegistration.getCredentialsId(); return new CassandraEpRegistrationByEndpointId(endpointId, credentialsId); diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraModelConstants.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraModelConstants.java index a6d25ae8c7..3db2969893 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraModelConstants.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraModelConstants.java @@ -125,7 +125,7 @@ private CassandraModelConstants() { public static final String EP_USER_ENDPOINT_IDS_PROPERTY = "ep_ids"; /** - * CassandraEPByAccessToken constants. + * CassandraEpByAccessToken constants. */ public static final String EP_BY_ACCESS_TOKEN_COLUMN_FAMILY_NAME = "access_token_eps"; public static final String EP_BY_ACCESS_TOKEN_ACCESS_TOKEN_PROPERTY = @@ -134,7 +134,7 @@ private CassandraModelConstants() { ENDPOINT_KEY_HASH_PROPERTY; /** - * CassandraEPByAppId constants. + * CassandraEpByAppId constants. */ public static final String EP_BY_APP_ID_COLUMN_FAMILY_NAME = "app_eps"; public static final String EP_BY_APP_ID_APPLICATION_ID_PROPERTY = APPLICATION_ID_PROPERTY; @@ -150,7 +150,7 @@ private CassandraModelConstants() { ENDPOINT_KEY_HASH_PROPERTY; /** - * CassandraEPByEndpointGroupId constants. + * CassandraEpByEndpointGroupId constants. */ public static final String EP_BY_ENDPOINT_GROUP_ID_COLUMN_FAMILY_NAME = "endpoint_group_id_eps"; diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/type/CassandraEndpointGroupState.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/type/CassandraEndpointGroupState.java index d77a1f6894..ab1b4d9295 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/type/CassandraEndpointGroupState.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/type/CassandraEndpointGroupState.java @@ -31,7 +31,8 @@ import java.io.Serializable; @UDT(name = ENDPOINT_GROUP_STATE_USER_TYPE_NAME) -public final class CassandraEndpointGroupState implements ToDto, Serializable { +public final class CassandraEndpointGroupState + implements ToDto, Serializable { @Transient private static final long serialVersionUID = -1658174097110691624L; @@ -77,23 +78,31 @@ public void setConfigurationId(String configurationId) { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - CassandraEndpointGroupState that = (CassandraEndpointGroupState) o; + CassandraEndpointGroupState that = (CassandraEndpointGroupState) object; - if (configurationId != null ? !configurationId.equals(that.configurationId) : that.configurationId != null) { + if (configurationId != null + ? !configurationId.equals(that.configurationId) + : that.configurationId != null) { return false; } - if (endpointGroupId != null ? !endpointGroupId.equals(that.endpointGroupId) : that.endpointGroupId != null) { + + if (endpointGroupId != null + ? !endpointGroupId.equals(that.endpointGroupId) + : that.endpointGroupId != null) { return false; } - if (profileFilterId != null ? !profileFilterId.equals(that.profileFilterId) : that.profileFilterId != null) { + + if (profileFilterId != null + ? !profileFilterId.equals(that.profileFilterId) + : that.profileFilterId != null) { return false; } @@ -110,11 +119,11 @@ public int hashCode() { @Override public String toString() { - return "CassandraEndpointGroupState{" + - "endpointGroupId='" + endpointGroupId + '\'' + - ", profileFilterId='" + profileFilterId + '\'' + - ", configurationId='" + configurationId + '\'' + - '}'; + return "CassandraEndpointGroupState{" + + "endpointGroupId='" + endpointGroupId + '\'' + + ", profileFilterId='" + profileFilterId + '\'' + + ", configurationId='" + configurationId + '\'' + + '}'; } @Override diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/type/CassandraEventClassFamilyVersionState.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/type/CassandraEventClassFamilyVersionState.java index 0ef1a11622..47d1752ad2 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/type/CassandraEventClassFamilyVersionState.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/type/CassandraEventClassFamilyVersionState.java @@ -30,7 +30,8 @@ import java.io.Serializable; @UDT(name = EVENT_CLASS_FAMILY_VERSION_STATE_USER_TYPE_NAME) -public final class CassandraEventClassFamilyVersionState implements ToDto, Serializable { +public final class CassandraEventClassFamilyVersionState + implements ToDto, Serializable { @Transient private static final long serialVersionUID = 3766947955702551264L; diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/hash/ConsistentHashResolver.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/hash/ConsistentHashResolver.java index 83d595595f..ef5714f40c 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/hash/ConsistentHashResolver.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/hash/ConsistentHashResolver.java @@ -48,8 +48,8 @@ public class ConsistentHashResolver implements OperationsServerResolver { protected MessageDigest initialValue() { try { return MessageDigest.getInstance(MD5); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); + } catch (NoSuchAlgorithmException exception) { + throw new RuntimeException(exception); } } }; diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ClientSync.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ClientSync.java index ef1dfe259b..155347a7ad 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ClientSync.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ClientSync.java @@ -54,9 +54,14 @@ public ClientSync() { } - public ClientSync(int requestId, ClientSyncMetaData clientSyncMetaData, ProfileClientSync profileSync, - ConfigurationClientSync configurationSync, NotificationClientSync notificationSync, UserClientSync userSync, - EventClientSync eventSync, LogClientSync logSync) { + public ClientSync(int requestId, + ClientSyncMetaData clientSyncMetaData, + ProfileClientSync profileSync, + ConfigurationClientSync configurationSync, + NotificationClientSync notificationSync, + UserClientSync userSync, + EventClientSync eventSync, + LogClientSync logSync) { this.requestId = requestId; this.clientSyncMetaData = clientSyncMetaData; this.profileSync = profileSync; @@ -189,29 +194,68 @@ public void setUseConfigurationRawSchema(boolean useConfigurationRawSchema) { } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + public boolean equals(Object object) { + if (this == object) { + return true; + } + + if (object == null || getClass() != object.getClass()) { + return false; + } + + ClientSync that = (ClientSync) object; + + if (requestId != that.requestId) { + return false; + } + + if (forceConfigurationSync != that.forceConfigurationSync) { + return false; + } + + if (forceNotificationSync != that.forceNotificationSync) { + return false; + } + + if (useConfigurationRawSchema != that.useConfigurationRawSchema) { + return false; + } - ClientSync that = (ClientSync) o; + if (clientSyncMetaData != null + ? !clientSyncMetaData.equals(that.clientSyncMetaData) + : that.clientSyncMetaData != null) { + return false; + } - if (requestId != that.requestId) return false; - if (forceConfigurationSync != that.forceConfigurationSync) return false; - if (forceNotificationSync != that.forceNotificationSync) return false; - if (useConfigurationRawSchema != that.useConfigurationRawSchema) return false; - if (clientSyncMetaData != null ? !clientSyncMetaData.equals(that.clientSyncMetaData) : that.clientSyncMetaData != null) + if (bootstrapSync != null + ? !bootstrapSync.equals(that.bootstrapSync) + : that.bootstrapSync != null) { return false; - if (bootstrapSync != null ? !bootstrapSync.equals(that.bootstrapSync) : that.bootstrapSync != null) + } + + if (profileSync != null ? !profileSync.equals(that.profileSync) : that.profileSync != null) { return false; - if (profileSync != null ? !profileSync.equals(that.profileSync) : that.profileSync != null) + } + + if (configurationSync != null + ? !configurationSync.equals(that.configurationSync) + : that.configurationSync != null) { return false; - if (configurationSync != null ? !configurationSync.equals(that.configurationSync) : that.configurationSync != null) + } + + if (notificationSync != null + ? !notificationSync.equals(that.notificationSync) + : that.notificationSync != null) { return false; - if (notificationSync != null ? !notificationSync.equals(that.notificationSync) : that.notificationSync != null) + } + + if (userSync != null ? !userSync.equals(that.userSync) : that.userSync != null) { return false; - if (userSync != null ? !userSync.equals(that.userSync) : that.userSync != null) return false; - if (eventSync != null ? !eventSync.equals(that.eventSync) : that.eventSync != null) + } + + if (eventSync != null ? !eventSync.equals(that.eventSync) : that.eventSync != null) { return false; + } return logSync != null ? logSync.equals(that.logSync) : that.logSync == null; } diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ClientSyncMetaData.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ClientSyncMetaData.java index 70c9525dcd..c5973d1972 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ClientSyncMetaData.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ClientSyncMetaData.java @@ -31,7 +31,11 @@ public ClientSyncMetaData() { /** * All-args constructor. */ - public ClientSyncMetaData(String applicationToken, String sdkToken, ByteBuffer endpointPublicKeyHash, ByteBuffer profileHash, Long timeout) { + public ClientSyncMetaData(String applicationToken, + String sdkToken, + ByteBuffer endpointPublicKeyHash, + ByteBuffer profileHash, + Long timeout) { this.applicationToken = applicationToken; this.sdkToken = sdkToken; this.endpointPublicKeyHash = endpointPublicKeyHash; @@ -112,23 +116,27 @@ public void setSdkToken(String sdkToken) { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - ClientSyncMetaData that = (ClientSyncMetaData) o; + ClientSyncMetaData that = (ClientSyncMetaData) object; if (timeout != that.timeout) { return false; } - if (applicationToken != null ? !applicationToken.equals(that.applicationToken) : that.applicationToken != null) { + if (applicationToken != null + ? !applicationToken.equals(that.applicationToken) + : that.applicationToken != null) { return false; } - if (endpointPublicKeyHash != null ? !endpointPublicKeyHash.equals(that.endpointPublicKeyHash) : that.endpointPublicKeyHash != null) { + if (endpointPublicKeyHash != null + ? !endpointPublicKeyHash.equals(that.endpointPublicKeyHash) + : that.endpointPublicKeyHash != null) { return false; } if (profileHash != null ? !profileHash.equals(that.profileHash) : that.profileHash != null) { diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ConfigurationClientSync.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ConfigurationClientSync.java index 5918d153a3..fcd041e3cf 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ConfigurationClientSync.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ConfigurationClientSync.java @@ -59,7 +59,7 @@ public boolean isResyncOnly() { } /** - * Sets that client is interested only in resync delta encoded using base schema + * Sets that client is interested only in resync delta encoded using base schema. */ public void setResyncOnly(boolean resyncOnly) { this.resyncOnly = resyncOnly; diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ConfigurationServerSync.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ConfigurationServerSync.java index 8ad305be1f..f7aabc7de5 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ConfigurationServerSync.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ConfigurationServerSync.java @@ -30,7 +30,9 @@ public ConfigurationServerSync() { /** * All-args constructor. */ - public ConfigurationServerSync(int appStateSeqNumber, SyncResponseStatus responseStatus, ByteBuffer confSchemaBody, + public ConfigurationServerSync(int appStateSeqNumber, + SyncResponseStatus responseStatus, + ByteBuffer confSchemaBody, ByteBuffer confDeltaBody) { this.responseStatus = responseStatus; this.confSchemaBody = confSchemaBody; @@ -86,22 +88,33 @@ public void setConfDeltaBody(ByteBuffer value) { } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + public boolean equals(Object object) { + if (this == object) { + return true; + } + + if (object == null || getClass() != object.getClass()) { + return false; + } - ConfigurationServerSync that = (ConfigurationServerSync) o; + ConfigurationServerSync that = (ConfigurationServerSync) object; - if (confDeltaBody != null ? !confDeltaBody.equals(that.confDeltaBody) : that.confDeltaBody != null) { + if (confDeltaBody != null + ? !confDeltaBody.equals(that.confDeltaBody) + : that.confDeltaBody != null) { return false; } - if (confSchemaBody != null ? !confSchemaBody.equals(that.confSchemaBody) : that.confSchemaBody != null) { + if (confSchemaBody != null + ? !confSchemaBody.equals(that.confSchemaBody) + : that.confSchemaBody != null) { return false; } - if (responseStatus != that.responseStatus) return false; - { - return true; + + if (responseStatus != that.responseStatus) { + return false; } + + return true; } @Override diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/Event.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/Event.java index e9bfaa835f..3e6a8354d2 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/Event.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/Event.java @@ -20,7 +20,7 @@ public final class Event { private int seqNum; - private String eventClassFQN; + private String eventClassFqn; private ByteBuffer eventData; private String source; private String target; @@ -31,9 +31,10 @@ public Event() { /** * All-args constructor. */ - public Event(int seqNum, String eventClassFQN, ByteBuffer eventData, String source, String target) { + public Event(int seqNum, String eventClassFqn, ByteBuffer eventData, + String source, String target) { this.seqNum = seqNum; - this.eventClassFQN = eventClassFQN; + this.eventClassFqn = eventClassFqn; this.eventData = eventData; this.source = source; this.target = target; @@ -56,19 +57,19 @@ public void setSeqNum(int value) { } /** - * Gets the value of the 'eventClassFQN' field. + * Gets the value of the 'eventClassFqn' field. */ - public String getEventClassFQN() { - return eventClassFQN; + public String getEventClassFqn() { + return eventClassFqn; } /** - * Sets the value of the 'eventClassFQN' field. + * Sets the value of the 'eventClassFqn' field. * * @param value the value to set. */ - public void setEventClassFQN(String value) { - this.eventClassFQN = value; + public void setEventClassFqn(String value) { + this.eventClassFqn = value; } /** @@ -123,7 +124,7 @@ public void setTarget(String value) { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((eventClassFQN == null) ? 0 : eventClassFQN.hashCode()); + result = prime * result + ((eventClassFqn == null) ? 0 : eventClassFqn.hashCode()); result = prime * result + ((eventData == null) ? 0 : eventData.hashCode()); result = prime * result + seqNum; result = prime * result + ((source == null) ? 0 : source.hashCode()); @@ -143,11 +144,11 @@ public boolean equals(Object obj) { return false; } Event other = (Event) obj; - if (eventClassFQN == null) { - if (other.eventClassFQN != null) { + if (eventClassFqn == null) { + if (other.eventClassFqn != null) { return false; } - } else if (!eventClassFQN.equals(other.eventClassFQN)) { + } else if (!eventClassFqn.equals(other.eventClassFqn)) { return false; } if (eventData == null) { @@ -182,8 +183,8 @@ public String toString() { StringBuilder builder = new StringBuilder(); builder.append("Event [seqNum="); builder.append(seqNum); - builder.append(", eventClassFQN="); - builder.append(eventClassFQN); + builder.append(", eventClassFqn="); + builder.append(eventClassFqn); builder.append(", eventData="); builder.append(eventData); builder.append(", source="); diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventClientSync.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventClientSync.java index 7d2eb1a212..91e5cf235d 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventClientSync.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventClientSync.java @@ -26,7 +26,9 @@ public final class EventClientSync { public EventClientSync() { } - public EventClientSync(boolean seqNumberRequest, List eventListenersRequests, List events) { + public EventClientSync(boolean seqNumberRequest, + List eventListenersRequests, + List events) { super(); this.seqNumberRequest = seqNumberRequest; this.eventListenersRequests = eventListenersRequests; @@ -77,7 +79,8 @@ public void setEvents(List value) { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((eventListenersRequests == null) ? 0 : eventListenersRequests.hashCode()); + result = prime * result + + ((eventListenersRequests == null) ? 0 : eventListenersRequests.hashCode()); result = prime * result + ((events == null) ? 0 : events.hashCode()); result = prime * result + (seqNumberRequest ? 1231 : 1237); return result; diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventListenersRequest.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventListenersRequest.java index 3ecaff4013..0930da1296 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventListenersRequest.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventListenersRequest.java @@ -20,7 +20,7 @@ public final class EventListenersRequest { private int requestId; - private List eventClassFQNs; + private List eventClassFqns; public EventListenersRequest() { } @@ -28,9 +28,9 @@ public EventListenersRequest() { /** * All-args constructor. */ - public EventListenersRequest(int requestId, List eventClassFQNs) { + public EventListenersRequest(int requestId, List eventClassFqns) { this.requestId = requestId; - this.eventClassFQNs = eventClassFQNs; + this.eventClassFqns = eventClassFqns; } /** @@ -50,26 +50,26 @@ public void setRequestId(int value) { } /** - * Gets the value of the 'eventClassFQNs' field. + * Gets the value of the 'eventClassFqns' field. */ - public List getEventClassFQNs() { - return eventClassFQNs; + public List getEventClassFqns() { + return eventClassFqns; } /** - * Sets the value of the 'eventClassFQNs' field. + * Sets the value of the 'eventClassFqns' field. * * @param value the value to set. */ - public void setEventClassFQNs(List value) { - this.eventClassFQNs = value; + public void setEventClassFqns(List value) { + this.eventClassFqns = value; } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((eventClassFQNs == null) ? 0 : eventClassFQNs.hashCode()); + result = prime * result + ((eventClassFqns == null) ? 0 : eventClassFqns.hashCode()); result = prime * result + requestId; return result; } @@ -86,11 +86,11 @@ public boolean equals(Object obj) { return false; } EventListenersRequest other = (EventListenersRequest) obj; - if (eventClassFQNs == null) { - if (other.eventClassFQNs != null) { + if (eventClassFqns == null) { + if (other.eventClassFqns != null) { return false; } - } else if (!eventClassFQNs.equals(other.eventClassFQNs)) { + } else if (!eventClassFqns.equals(other.eventClassFqns)) { return false; } if (requestId != other.requestId) { @@ -104,8 +104,8 @@ public String toString() { StringBuilder builder = new StringBuilder(); builder.append("EventListenersRequest [requestId="); builder.append(requestId); - builder.append(", eventClassFQNs="); - builder.append(eventClassFQNs); + builder.append(", eventClassFqns="); + builder.append(eventClassFqns); builder.append("]"); return builder.toString(); } diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventListenersResponse.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventListenersResponse.java index e4efff7ea3..acc061c0d5 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventListenersResponse.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventListenersResponse.java @@ -85,15 +85,15 @@ public void setResult(SyncStatus value) { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - EventListenersResponse that = (EventListenersResponse) o; + EventListenersResponse that = (EventListenersResponse) object; if (requestId != that.requestId) { return false; diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventSequenceNumberResponse.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventSequenceNumberResponse.java index f42ac06011..960db099f8 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventSequenceNumberResponse.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventSequenceNumberResponse.java @@ -46,15 +46,15 @@ public void setSeqNum(Integer value) { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - EventSequenceNumberResponse that = (EventSequenceNumberResponse) o; + EventSequenceNumberResponse that = (EventSequenceNumberResponse) object; if (seqNum != that.seqNum) { return false; diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventServerSync.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventServerSync.java index 01cdaea499..2dccc245e2 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventServerSync.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/EventServerSync.java @@ -86,22 +86,28 @@ public void setEvents(List value) { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - EventServerSync that = (EventServerSync) o; + EventServerSync that = (EventServerSync) object; - if (eventListenersResponses != null ? !eventListenersResponses.equals(that.eventListenersResponses) : that.eventListenersResponses != null) { + if (eventListenersResponses != null + ? !eventListenersResponses.equals(that.eventListenersResponses) + : that.eventListenersResponses != null) { return false; } - if (eventSequenceNumberResponse != null ? !eventSequenceNumberResponse.equals(that.eventSequenceNumberResponse) : that.eventSequenceNumberResponse != null) { + + if (eventSequenceNumberResponse != null + ? !eventSequenceNumberResponse.equals(that.eventSequenceNumberResponse) + : that.eventSequenceNumberResponse != null) { return false; } + if (events != null ? !events.equals(that.events) : that.events != null) { return false; } @@ -112,7 +118,8 @@ public boolean equals(Object o) { @Override public int hashCode() { int result = eventSequenceNumberResponse != null ? eventSequenceNumberResponse.hashCode() : 0; - result = 31 * result + (eventListenersResponses != null ? eventListenersResponses.hashCode() : 0); + result = 31 * result + + (eventListenersResponses != null ? eventListenersResponses.hashCode() : 0); result = 31 * result + (events != null ? events.hashCode() : 0); return result; } diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/NotificationClientSync.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/NotificationClientSync.java index 202cde90e6..2a3fcbd21e 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/NotificationClientSync.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/NotificationClientSync.java @@ -103,8 +103,10 @@ public void setSubscriptionCommands(List subscriptionComman public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((acceptedUnicastNotifications == null) ? 0 : acceptedUnicastNotifications.hashCode()); - result = prime * result + ((subscriptionCommands == null) ? 0 : subscriptionCommands.hashCode()); + result = prime * result + + ((acceptedUnicastNotifications == null) ? 0 : acceptedUnicastNotifications.hashCode()); + result = prime * result + + ((subscriptionCommands == null) ? 0 : subscriptionCommands.hashCode()); result = prime * result + topicListHash; result = prime * result + ((topicStates == null) ? 0 : topicStates.hashCode()); return result; diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/NotificationServerSync.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/NotificationServerSync.java index 26ba556c88..30f45c86aa 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/NotificationServerSync.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/NotificationServerSync.java @@ -34,7 +34,9 @@ public NotificationServerSync() { /** * All-args constructor. */ - public NotificationServerSync(SyncResponseStatus responseStatus, List notifications, List availableTopics) { + public NotificationServerSync(SyncResponseStatus responseStatus, + List notifications, + List availableTopics) { this.responseStatus = responseStatus; this.notifications = notifications; this.availableTopics = availableTopics; @@ -89,22 +91,28 @@ public void setAvailableTopics(List value) { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - NotificationServerSync that = (NotificationServerSync) o; + NotificationServerSync that = (NotificationServerSync) object; - if (availableTopics != null ? !availableTopics.equals(that.availableTopics) : that.availableTopics != null) { + if (availableTopics != null + ? !availableTopics.equals(that.availableTopics) + : that.availableTopics != null) { return false; } - if (notifications != null ? !notifications.equals(that.notifications) : that.notifications != null) { + + if (notifications != null + ? !notifications.equals(that.notifications) + : that.notifications != null) { return false; } + if (responseStatus != that.responseStatus) { return false; } diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ProfileServerSync.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ProfileServerSync.java index 5cf7a2df67..b27c453b79 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ProfileServerSync.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ProfileServerSync.java @@ -47,15 +47,15 @@ public void setResponseStatus(SyncResponseStatus value) { @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - ProfileServerSync that = (ProfileServerSync) o; + ProfileServerSync that = (ProfileServerSync) object; if (responseStatus != that.responseStatus) { return false; diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ServerSync.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ServerSync.java index bf1e0bef40..2f85dbb48d 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ServerSync.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/ServerSync.java @@ -44,8 +44,10 @@ public ServerSync() { * All-args constructor. */ public ServerSync(int requestId, SyncStatus status, ProfileServerSync profileSync, - ConfigurationServerSync configurationSync, NotificationServerSync notificationSync, UserServerSync userSync, - EventServerSync eventSync, RedirectServerSync redirectSync, LogServerSync logSync) { + ConfigurationServerSync configurationSync, + NotificationServerSync notificationSync, UserServerSync userSync, + EventServerSync eventSync, RedirectServerSync redirectSync, + LogServerSync logSync) { this.requestId = requestId; this.status = status; this.profileSync = profileSync; @@ -74,19 +76,6 @@ public static ServerSync deepCopy(ServerSync source) { return copy; } - public static void cleanup(ServerSync syncResponse) { - if (syncResponse == null) { - return; - } - syncResponse.setUserSync(null); - syncResponse.setRedirectSync(null); - syncResponse.setProfileSync(null); - syncResponse.setNotificationSync(null); - syncResponse.setLogSync(null); - syncResponse.setEventSync(null); - syncResponse.setConfigurationSync(null); - } - private static ConfigurationServerSync deepCopy(ConfigurationServerSync source) { if (source == null) { return null; @@ -122,7 +111,8 @@ private static LogServerSync deepCopy(LogServerSync source) { if (source.getDeliveryStatuses() != null) { List statusList = new ArrayList<>(source.getDeliveryStatuses().size()); for (LogDeliveryStatus status : source.getDeliveryStatuses()) { - statusList.add(new LogDeliveryStatus(status.getRequestId(), status.getResult(), status.getErrorCode())); + statusList.add(new LogDeliveryStatus( + status.getRequestId(), status.getResult(), status.getErrorCode())); } return new LogServerSync(statusList); } else { @@ -171,19 +161,36 @@ private static UserServerSync deepCopy(UserServerSync source) { copy.setEndpointDetachResponses(new ArrayList<>(source.getEndpointDetachResponses())); } if (source.getUserAttachNotification() != null) { - copy.setUserAttachNotification(new UserAttachNotification(source.getUserAttachNotification().getUserExternalId(), source + copy.setUserAttachNotification(new UserAttachNotification( + source.getUserAttachNotification().getUserExternalId(), source .getUserAttachNotification().getEndpointAccessToken())); } if (source.getUserAttachResponse() != null) { UserAttachResponse uarSource = source.getUserAttachResponse(); - copy.setUserAttachResponse(new UserAttachResponse(uarSource.getResult(), uarSource.getErrorCode(), uarSource.getErrorReason())); + copy.setUserAttachResponse(new UserAttachResponse( + uarSource.getResult(), uarSource.getErrorCode(), uarSource.getErrorReason())); } if (source.getUserDetachNotification() != null) { - copy.setUserDetachNotification(new UserDetachNotification(source.getUserDetachNotification().getEndpointAccessToken())); + copy.setUserDetachNotification(new UserDetachNotification( + source.getUserDetachNotification().getEndpointAccessToken())); } return copy; } + public static void cleanup(ServerSync syncResponse) { + if (syncResponse == null) { + return; + } + syncResponse.setUserSync(null); + syncResponse.setRedirectSync(null); + syncResponse.setProfileSync(null); + syncResponse.setNotificationSync(null); + syncResponse.setLogSync(null); + syncResponse.setEventSync(null); + syncResponse.setConfigurationSync(null); + } + + /** * Gets the value of the 'requestId' field. */ @@ -337,43 +344,58 @@ public void setBootstrapSync(BootstrapServerSync bootstrapSync) { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - ServerSync that = (ServerSync) o; + ServerSync that = (ServerSync) object; if (requestId != that.requestId) { return false; } - if (bootstrapSync != null ? !bootstrapSync.equals(that.bootstrapSync) : that.bootstrapSync != null) { + if (bootstrapSync != null + ? !bootstrapSync.equals(that.bootstrapSync) + : that.bootstrapSync != null) { return false; } - if (configurationSync != null ? !configurationSync.equals(that.configurationSync) : that.configurationSync != null) { + + if (configurationSync != null + ? !configurationSync.equals(that.configurationSync) + : that.configurationSync != null) { return false; } + if (eventSync != null ? !eventSync.equals(that.eventSync) : that.eventSync != null) { return false; } + if (logSync != null ? !logSync.equals(that.logSync) : that.logSync != null) { return false; } - if (notificationSync != null ? !notificationSync.equals(that.notificationSync) : that.notificationSync != null) { + + if (notificationSync != null + ? !notificationSync.equals(that.notificationSync) + : that.notificationSync != null) { return false; } + if (profileSync != null ? !profileSync.equals(that.profileSync) : that.profileSync != null) { return false; } - if (redirectSync != null ? !redirectSync.equals(that.redirectSync) : that.redirectSync != null) { + if (redirectSync != null + ? !redirectSync.equals(that.redirectSync) + : that.redirectSync != null) { return false; } + if (status != that.status) { return false; } + if (userSync != null ? !userSync.equals(that.userSync) : that.userSync != null) { return false; } diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/Topic.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/Topic.java index 10f580ea43..cee8425c68 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/Topic.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/Topic.java @@ -98,15 +98,15 @@ public void setSubscriptionType(SubscriptionType value) { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - Topic topic = (Topic) o; + Topic topic = (Topic) object; if (id != null ? !id.equals(topic.id) : topic.id != null) { return false; diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserAttachNotification.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserAttachNotification.java index ed0377055a..483a4f9897 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserAttachNotification.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserAttachNotification.java @@ -64,20 +64,25 @@ public void setEndpointAccessToken(String value) { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - UserAttachNotification that = (UserAttachNotification) o; + UserAttachNotification that = (UserAttachNotification) object; - if (endpointAccessToken != null ? !endpointAccessToken.equals(that.endpointAccessToken) : that.endpointAccessToken != null) { + if (endpointAccessToken != null + ? !endpointAccessToken.equals(that.endpointAccessToken) + : that.endpointAccessToken != null) { return false; } - if (userExternalId != null ? !userExternalId.equals(that.userExternalId) : that.userExternalId != null) { + + if (userExternalId != null + ? !userExternalId.equals(that.userExternalId) + : that.userExternalId != null) { return false; } diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserAttachResponse.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserAttachResponse.java index 37ad163e6f..0a89b71794 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserAttachResponse.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserAttachResponse.java @@ -27,7 +27,9 @@ public UserAttachResponse() { /** * All-args constructor. */ - public UserAttachResponse(SyncStatus result, UserVerifierErrorCode errorCode, String errorReason) { + public UserAttachResponse(SyncStatus result, + UserVerifierErrorCode errorCode, + String errorReason) { this.result = result; this.errorCode = errorCode; this.errorReason = errorReason; @@ -58,15 +60,15 @@ public String getErrorReason() { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - UserAttachResponse that = (UserAttachResponse) o; + UserAttachResponse that = (UserAttachResponse) object; if (errorCode != that.errorCode) { return false; diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserClientSync.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserClientSync.java index 482a88254d..7ef6b712d9 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserClientSync.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserClientSync.java @@ -29,7 +29,8 @@ public UserClientSync() { /** * All-args constructor. */ - public UserClientSync(UserAttachRequest userAttachRequest, List endpointAttachRequests, + public UserClientSync(UserAttachRequest userAttachRequest, + List endpointAttachRequests, List endpointDetachRequests) { this.userAttachRequest = userAttachRequest; this.endpointAttachRequests = endpointAttachRequests; @@ -88,9 +89,12 @@ public void setEndpointDetachRequests(List value) { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((endpointAttachRequests == null) ? 0 : endpointAttachRequests.hashCode()); - result = prime * result + ((endpointDetachRequests == null) ? 0 : endpointDetachRequests.hashCode()); - result = prime * result + ((userAttachRequest == null) ? 0 : userAttachRequest.hashCode()); + result = prime * result + + ((endpointAttachRequests == null) ? 0 : endpointAttachRequests.hashCode()); + result = prime * result + + ((endpointDetachRequests == null) ? 0 : endpointDetachRequests.hashCode()); + result = prime * result + + ((userAttachRequest == null) ? 0 : userAttachRequest.hashCode()); return result; } diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserDetachNotification.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserDetachNotification.java index 9382835ace..2745d9afab 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserDetachNotification.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserDetachNotification.java @@ -46,17 +46,19 @@ public void setEndpointAccessToken(String value) { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - UserDetachNotification that = (UserDetachNotification) o; + UserDetachNotification that = (UserDetachNotification) object; - if (endpointAccessToken != null ? !endpointAccessToken.equals(that.endpointAccessToken) : that.endpointAccessToken != null) { + if (endpointAccessToken != null + ? !endpointAccessToken.equals(that.endpointAccessToken) + : that.endpointAccessToken != null) { return false; } diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserServerSync.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserServerSync.java index cae56cd3bd..1060102e0b 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserServerSync.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/UserServerSync.java @@ -31,8 +31,10 @@ public UserServerSync() { /** * All-args constructor. */ - public UserServerSync(UserAttachResponse userAttachResponse, UserAttachNotification userAttachNotification, - UserDetachNotification userDetachNotification, List endpointAttachResponses, + public UserServerSync(UserAttachResponse userAttachResponse, + UserAttachNotification userAttachNotification, + UserDetachNotification userDetachNotification, + List endpointAttachResponses, List endpointDetachResponses) { this.userAttachResponse = userAttachResponse; this.userAttachNotification = userAttachNotification; @@ -127,29 +129,39 @@ public void setEndpointDetachResponses(List value) { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - UserServerSync that = (UserServerSync) o; + UserServerSync that = (UserServerSync) object; - if (endpointAttachResponses != null ? !endpointAttachResponses.equals(that.endpointAttachResponses) : that.endpointAttachResponses != null) { + if (endpointAttachResponses != null + ? !endpointAttachResponses.equals(that.endpointAttachResponses) + : that.endpointAttachResponses != null) { return false; } - if (endpointDetachResponses != null ? !endpointDetachResponses.equals(that.endpointDetachResponses) : that.endpointDetachResponses != null) { + if (endpointDetachResponses != null + ? !endpointDetachResponses.equals(that.endpointDetachResponses) + : that.endpointDetachResponses != null) { return false; } - if (userAttachNotification != null ? !userAttachNotification.equals(that.userAttachNotification) : that.userAttachNotification != null) { + if (userAttachNotification != null + ? !userAttachNotification.equals(that.userAttachNotification) + : that.userAttachNotification != null) { return false; } - if (userAttachResponse != null ? !userAttachResponse.equals(that.userAttachResponse) : that.userAttachResponse != null) { + if (userAttachResponse != null + ? !userAttachResponse.equals(that.userAttachResponse) + : that.userAttachResponse != null) { return false; } - if (userDetachNotification != null ? !userDetachNotification.equals(that.userDetachNotification) : that.userDetachNotification != null) { + if (userDetachNotification != null + ? !userDetachNotification.equals(that.userDetachNotification) + : that.userDetachNotification != null) { return false; } @@ -159,10 +171,14 @@ public boolean equals(Object o) { @Override public int hashCode() { int result = userAttachResponse != null ? userAttachResponse.hashCode() : 0; - result = 31 * result + (userAttachNotification != null ? userAttachNotification.hashCode() : 0); - result = 31 * result + (userDetachNotification != null ? userDetachNotification.hashCode() : 0); - result = 31 * result + (endpointAttachResponses != null ? endpointAttachResponses.hashCode() : 0); - result = 31 * result + (endpointDetachResponses != null ? endpointDetachResponses.hashCode() : 0); + result = 31 * result + (userAttachNotification != null + ? userAttachNotification.hashCode() : 0); + result = 31 * result + (userDetachNotification != null + ? userDetachNotification.hashCode() : 0); + result = 31 * result + (endpointAttachResponses != null + ? endpointAttachResponses.hashCode() : 0); + result = 31 * result + (endpointDetachResponses != null + ? endpointDetachResponses.hashCode() : 0); return result; } diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/bootstrap/ProtocolConnectionData.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/bootstrap/ProtocolConnectionData.java index 8bed1e8487..c88ee6ea04 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/bootstrap/ProtocolConnectionData.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/bootstrap/ProtocolConnectionData.java @@ -26,7 +26,9 @@ public final class ProtocolConnectionData { private final ProtocolVersionId protocolVersionId; private final byte[] connectionData; - public ProtocolConnectionData(int accessPointId, ProtocolVersionId protocolVersionId, byte[] connectionData) { + public ProtocolConnectionData(int accessPointId, + ProtocolVersionId protocolVersionId, + byte[] connectionData) { super(); this.accessPointId = accessPointId; this.protocolVersionId = protocolVersionId; diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/bootstrap/ProtocolVersionId.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/bootstrap/ProtocolVersionId.java index 7cf4227230..3b3faab4ff 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/bootstrap/ProtocolVersionId.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/bootstrap/ProtocolVersionId.java @@ -17,7 +17,7 @@ package org.kaaproject.kaa.server.sync.bootstrap; /** - * Simple immutable object that + * Simple immutable object that. * * @author Andrey Shvayka */ diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/AvroEncDec.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/AvroEncDec.java index 1ddb26eb1a..327ac66dff 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/AvroEncDec.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/AvroEncDec.java @@ -169,7 +169,8 @@ public static org.kaaproject.kaa.common.endpoint.gen.Event convert(Event event) if (event == null) { return null; } - return new org.kaaproject.kaa.common.endpoint.gen.Event(event.getSeqNum(), event.getEventClassFQN(), event.getEventData(), + return new org.kaaproject.kaa.common.endpoint.gen.Event( + event.getSeqNum(), event.getEventClassFqn(), event.getEventData(), event.getSource(), event.getTarget()); } @@ -177,14 +178,16 @@ public static org.kaaproject.kaa.common.endpoint.gen.Event convert(Event event) * Converts Avro {@link org.kaaproject.kaa.common.endpoint.gen.Event} to * {@link Event}. * - * @param source the avro structure + * @param event the avro structure * @return the event */ public static Event convert(org.kaaproject.kaa.common.endpoint.gen.Event event) { if (event == null) { return null; } - return new Event(event.getSeqNum(), event.getEventClassFQN(), event.getEventData(), event.getSource(), event.getTarget()); + return new Event( + event.getSeqNum(), event.getEventClassFQN(), + event.getEventData(), event.getSource(), event.getTarget()); } private static SyncResponseResultType convert(org.kaaproject.kaa.server.sync.SyncStatus status) { @@ -209,16 +212,19 @@ private static BootstrapSyncResponse convert(BootstrapServerSync bootstrapSync) if (bootstrapSync == null) { return null; } - return new BootstrapSyncResponse(bootstrapSync.getRequestId(), convert(bootstrapSync.getProtocolList())); + return new BootstrapSyncResponse( + bootstrapSync.getRequestId(), convert(bootstrapSync.getProtocolList())); } private static List convert(Set source) { if (source == null) { return Collections.emptyList(); } - List result = new ArrayList(source.size()); + List result = new ArrayList<>(source.size()); for (ProtocolConnectionData pcd : source) { - result.add(new ProtocolMetaData(pcd.getAccessPointId(), new ProtocolVersionPair(pcd.getProtocolId(), pcd.getProtocolVersion()), + result.add(new ProtocolMetaData( + pcd.getAccessPointId(), + new ProtocolVersionPair(pcd.getProtocolId(), pcd.getProtocolVersion()), ByteBuffer.wrap(pcd.getConnectionData()))); } return result; @@ -238,7 +244,8 @@ private static ProfileSyncResponse convert(ProfileServerSync profileSyncResponse return new ProfileSyncResponse(convert(profileSyncResponse.getResponseStatus())); } - private static SyncResponseStatus convert(org.kaaproject.kaa.server.sync.SyncResponseStatus responseStatus) { + private static SyncResponseStatus convert( + org.kaaproject.kaa.server.sync.SyncResponseStatus responseStatus) { if (responseStatus == null) { return null; } @@ -274,14 +281,18 @@ private static NotificationSyncResponse convert(NotificationServerSync source) { if (source.getAvailableTopics() != null) { List topics = new ArrayList<>(source.getAvailableTopics().size()); for (org.kaaproject.kaa.server.sync.Topic topic : source.getAvailableTopics()) { - topics.add(new Topic(topic.getIdAsLong(), topic.getName(), convert(topic.getSubscriptionType()))); + topics.add(new Topic( + topic.getIdAsLong(), topic.getName(), convert(topic.getSubscriptionType()))); } sync.setAvailableTopics(topics); } if (source.getNotifications() != null) { List notifications = new ArrayList<>(source.getNotifications().size()); for (org.kaaproject.kaa.server.sync.Notification notification : source.getNotifications()) { - notifications.add(new Notification(notification.getTopicIdAsLong(), convert(notification.getType()), notification.getUid(), + notifications.add(new Notification( + notification.getTopicIdAsLong(), + convert(notification.getType()), + notification.getUid(), notification.getSeqNumber(), notification.getBody())); } sync.setNotifications(notifications); @@ -295,19 +306,26 @@ private static EventSyncResponse convert(EventServerSync source) { } EventSyncResponse sync = new EventSyncResponse(); if (source.getEventSequenceNumberResponse() != null) { - sync.setEventSequenceNumberResponse(new EventSequenceNumberResponse(source.getEventSequenceNumberResponse().getSeqNum())); + sync.setEventSequenceNumberResponse(new EventSequenceNumberResponse( + source.getEventSequenceNumberResponse().getSeqNum())); } if (source.getEvents() != null) { - List events = new ArrayList<>(source.getEvents().size()); + List events = new ArrayList<>( + source.getEvents().size()); + for (Event event : source.getEvents()) { events.add(convert(event)); } sync.setEvents(events); } if (source.getEventListenersResponses() != null) { - List responses = new ArrayList<>(source.getEventListenersResponses().size()); - for (org.kaaproject.kaa.server.sync.EventListenersResponse response : source.getEventListenersResponses()) { - responses.add(new EventListenersResponse(response.getRequestId(), response.getListeners(), convert(response.getResult()))); + List responses = new ArrayList<>( + source.getEventListenersResponses().size()); + + for (org.kaaproject.kaa.server.sync.EventListenersResponse response + : source.getEventListenersResponses()) { + responses.add(new EventListenersResponse( + response.getRequestId(), response.getListeners(), convert(response.getResult()))); } sync.setEventListenersResponses(responses); } @@ -320,36 +338,47 @@ private static UserSyncResponse convert(UserServerSync source) { } UserSyncResponse sync = new UserSyncResponse(); if (source.getUserAttachNotification() != null) { - sync.setUserAttachNotification(new UserAttachNotification(source.getUserAttachNotification().getUserExternalId(), source + sync.setUserAttachNotification( + new UserAttachNotification(source.getUserAttachNotification().getUserExternalId(), source .getUserAttachNotification().getEndpointAccessToken())); } if (source.getUserDetachNotification() != null) { - sync.setUserDetachNotification(new UserDetachNotification(source.getUserDetachNotification().getEndpointAccessToken())); + sync.setUserDetachNotification(new UserDetachNotification( + source.getUserDetachNotification().getEndpointAccessToken())); } if (source.getUserAttachResponse() != null) { sync.setUserAttachResponse(convert(source.getUserAttachResponse())); } if (source.getEndpointAttachResponses() != null) { - List responses = new ArrayList<>(source.getEndpointAttachResponses().size()); - for (org.kaaproject.kaa.server.sync.EndpointAttachResponse response : source.getEndpointAttachResponses()) { - responses.add(new EndpointAttachResponse(response.getRequestId(), response.getEndpointKeyHash(), convert(response + List responses = new ArrayList<>( + source.getEndpointAttachResponses().size()); + for (org.kaaproject.kaa.server.sync.EndpointAttachResponse response + : source.getEndpointAttachResponses()) { + responses.add(new EndpointAttachResponse( + response.getRequestId(), response.getEndpointKeyHash(), convert(response .getResult()))); } sync.setEndpointAttachResponses(responses); } if (source.getEndpointDetachResponses() != null) { - List responses = new ArrayList<>(source.getEndpointDetachResponses().size()); - for (org.kaaproject.kaa.server.sync.EndpointDetachResponse response : source.getEndpointDetachResponses()) { - responses.add(new EndpointDetachResponse(response.getRequestId(), convert(response.getResult()))); + List responses = new ArrayList<>( + source.getEndpointDetachResponses().size()); + for (org.kaaproject.kaa.server.sync.EndpointDetachResponse response + : source.getEndpointDetachResponses()) { + responses.add(new EndpointDetachResponse( + response.getRequestId(), convert(response.getResult()))); } sync.setEndpointDetachResponses(responses); } return sync; } - private static UserAttachResponse convert(org.kaaproject.kaa.server.sync.UserAttachResponse source) { + private static UserAttachResponse convert( + org.kaaproject.kaa.server.sync.UserAttachResponse source) { UserAttachResponse response = new UserAttachResponse(); - response.setResult(source.getResult() == SyncStatus.SUCCESS ? SyncResponseResultType.SUCCESS : SyncResponseResultType.FAILURE); + response.setResult(source.getResult() == SyncStatus.SUCCESS + ? SyncResponseResultType.SUCCESS + : SyncResponseResultType.FAILURE); response.setErrorCode(convert(source.getErrorCode())); response.setErrorReason(source.getErrorReason()); return response; @@ -391,7 +420,8 @@ private static NotificationType convert(org.kaaproject.kaa.server.sync.Notificat } } - private static SubscriptionType convert(org.kaaproject.kaa.server.sync.SubscriptionType subscriptionType) { + private static SubscriptionType convert( + org.kaaproject.kaa.server.sync.SubscriptionType subscriptionType) { if (subscriptionType == null) { return null; } @@ -410,7 +440,7 @@ private static LogSyncResponse convert(LogServerSync source) { return null; } LogSyncResponse sync = new LogSyncResponse(); - List statuses = new ArrayList(); + List statuses = new ArrayList<>(); for (LogDeliveryStatus status : source.getDeliveryStatuses()) { statuses.add(convert(status)); } @@ -418,14 +448,19 @@ private static LogSyncResponse convert(LogServerSync source) { return sync; } - private static org.kaaproject.kaa.common.endpoint.gen.LogDeliveryStatus convert(LogDeliveryStatus source) { + private static org.kaaproject.kaa.common.endpoint.gen.LogDeliveryStatus convert( + LogDeliveryStatus source) { if (source == null) { return null; } - return new org.kaaproject.kaa.common.endpoint.gen.LogDeliveryStatus(source.getRequestId(), convert(source.getResult()), convert(source.getErrorCode())); + return new org.kaaproject.kaa.common.endpoint.gen.LogDeliveryStatus( + source.getRequestId(), + convert(source.getResult()), + convert(source.getErrorCode())); } - private static LogDeliveryErrorCode convert(org.kaaproject.kaa.server.sync.LogDeliveryErrorCode errorCode) { + private static LogDeliveryErrorCode convert( + org.kaaproject.kaa.server.sync.LogDeliveryErrorCode errorCode) { if (errorCode == null) { return null; } @@ -447,8 +482,9 @@ private static ClientSyncMetaData convert(SyncRequestMetaData source) { if (source == null) { return null; } - return new ClientSyncMetaData(null, source.getSdkToken(), source.getEndpointPublicKeyHash(), source.getProfileHash(), - source.getTimeout()); + return new ClientSyncMetaData( + null, source.getSdkToken(), source.getEndpointPublicKeyHash(), + source.getProfileHash(), source.getTimeout()); } private static BootstrapClientSync convert(BootstrapSyncRequest source) { @@ -495,11 +531,16 @@ private static NotificationClientSync convert(NotificationSyncRequest source) { NotificationClientSync sync = new NotificationClientSync(); sync.setTopicListHash(source.getTopicListHash()); if (source.getAcceptedUnicastNotifications() != null) { - sync.setAcceptedUnicastNotifications(new ArrayList(source.getAcceptedUnicastNotifications())); + sync.setAcceptedUnicastNotifications(new ArrayList<>( + source.getAcceptedUnicastNotifications())); } + if (source.getSubscriptionCommands() != null) { - List commands = new ArrayList(source.getSubscriptionCommands().size()); - for (org.kaaproject.kaa.common.endpoint.gen.SubscriptionCommand command : source.getSubscriptionCommands()) { + List commands = new ArrayList<>( + source.getSubscriptionCommands().size()); + + for (org.kaaproject.kaa.common.endpoint.gen.SubscriptionCommand command + : source.getSubscriptionCommands()) { SubscriptionCommand copy = new SubscriptionCommand(); copy.setTopicId(command.getTopicId()); switch (command.getCommand()) { @@ -540,9 +581,13 @@ private static EventClientSync convert(EventSyncRequest source) { sync.setEvents(events); } if (source.getEventListenersRequests() != null) { - List requests = new ArrayList(source.getEventListenersRequests().size()); - for (org.kaaproject.kaa.common.endpoint.gen.EventListenersRequest request : source.getEventListenersRequests()) { - requests.add(new EventListenersRequest(request.getRequestId(), request.getEventClassFQNs())); + List requests = new ArrayList<>( + source.getEventListenersRequests().size()); + + for (org.kaaproject.kaa.common.endpoint.gen.EventListenersRequest request + : source.getEventListenersRequests()) { + requests.add(new EventListenersRequest( + request.getRequestId(), request.getEventClassFQNs())); } sync.setEventListenersRequests(requests); } @@ -572,20 +617,29 @@ private static UserClientSync convert(UserSyncRequest source) { } UserClientSync sync = new UserClientSync(); if (source.getUserAttachRequest() != null) { - sync.setUserAttachRequest(new UserAttachRequest(source.getUserAttachRequest().getUserVerifierId(), source.getUserAttachRequest().getUserExternalId(), source - .getUserAttachRequest().getUserAccessToken())); + sync.setUserAttachRequest(new UserAttachRequest( + source.getUserAttachRequest().getUserVerifierId(), + source.getUserAttachRequest().getUserExternalId(), + source.getUserAttachRequest().getUserAccessToken())); } if (source.getEndpointAttachRequests() != null) { - List requests = new ArrayList<>(source.getEndpointAttachRequests().size()); - for (org.kaaproject.kaa.common.endpoint.gen.EndpointAttachRequest request : source.getEndpointAttachRequests()) { - requests.add(new EndpointAttachRequest(request.getRequestId(), request.getEndpointAccessToken())); + List requests = new ArrayList<>( + source.getEndpointAttachRequests().size()); + for (org.kaaproject.kaa.common.endpoint.gen.EndpointAttachRequest request + : source.getEndpointAttachRequests()) { + requests.add(new EndpointAttachRequest( + request.getRequestId(), request.getEndpointAccessToken())); } sync.setEndpointAttachRequests(requests); } if (source.getEndpointDetachRequests() != null) { - List requests = new ArrayList<>(source.getEndpointDetachRequests().size()); - for (org.kaaproject.kaa.common.endpoint.gen.EndpointDetachRequest request : source.getEndpointDetachRequests()) { - requests.add(new EndpointDetachRequest(request.getRequestId(), request.getEndpointKeyHash())); + List requests = new ArrayList<>( + source.getEndpointDetachRequests().size()); + + for (org.kaaproject.kaa.common.endpoint.gen.EndpointDetachRequest request + : source.getEndpointDetachRequests()) { + requests.add(new EndpointDetachRequest( + request.getRequestId(), request.getEndpointKeyHash())); } sync.setEndpointDetachRequests(requests); } @@ -626,8 +680,8 @@ public ClientSync decode(byte[] data) throws PlatformEncDecException { sync.setUseConfigurationRawSchema(false); LOG.trace("Decoded client sync {}", sync); return sync; - } catch (IOException e) { - throw new PlatformEncDecException(e); + } catch (IOException exception) { + throw new PlatformEncDecException(exception); } } @@ -654,8 +708,8 @@ public byte[] encode(ServerSync sync) throws PlatformEncDecException { LOG.trace("Encoded avro data {}", Arrays.toString(data)); } return data; - } catch (IOException e) { - throw new PlatformEncDecException(e); + } catch (IOException exception) { + throw new PlatformEncDecException(exception); } } } diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/BinaryEncDec.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/BinaryEncDec.java index 2be02e67c6..c4c654883c 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/BinaryEncDec.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/BinaryEncDec.java @@ -177,11 +177,11 @@ private static boolean hasOption(int options, int option) { return (options & option) > 0; } - private static String getUTF8String(ByteBuffer buf) { - return getUTF8String(buf, getIntFromUnsignedShort(buf)); + private static String getUtf8String(ByteBuffer buf) { + return getUtf8String(buf, getIntFromUnsignedShort(buf)); } - private static String getUTF8String(ByteBuffer buf, int size) { + private static String getUtf8String(ByteBuffer buf, int size) { return new String(getNewByteArray(buf, size), UTF8); } @@ -194,13 +194,6 @@ private static byte[] getNewByteArray(ByteBuffer buf, int size, boolean withPadd return array; } - private static void handlePadding(ByteBuffer buf, int size) { - int padding = size % PADDING_SIZE; - if (padding > 0) { - buf.position(buf.position() + (PADDING_SIZE - padding)); - } - } - private static byte[] getNewByteArray(ByteBuffer buf, int size) { return getNewByteArray(buf, size, true); } @@ -213,6 +206,13 @@ private static ByteBuffer getNewByteBuffer(ByteBuffer buf, int size, boolean wit return ByteBuffer.wrap(getNewByteArray(buf, size, withPadding)); } + private static void handlePadding(ByteBuffer buf, int size) { + int padding = size % PADDING_SIZE; + if (padding > 0) { + buf.position(buf.position() + (PADDING_SIZE - padding)); + } + } + /* * (non-Javadoc) * @@ -232,23 +232,26 @@ public ClientSync decode(byte[] data) throws PlatformEncDecException { } ByteBuffer buf = ByteBuffer.wrap(data); if (buf.remaining() < MIN_SIZE_OF_MESSAGE_HEADER) { - throw new PlatformEncDecException(MessageFormat.format("Message header is to small {0} to be kaa binary message!", + throw new PlatformEncDecException( + MessageFormat.format("Message header is to small {0} to be kaa binary message!", buf.capacity())); } int protocolId = buf.getInt(); if (protocolId != getId()) { - throw new PlatformEncDecException(MessageFormat.format("Unknown protocol id {0}!", protocolId)); + throw new PlatformEncDecException( + MessageFormat.format("Unknown protocol id {0}!", protocolId)); } int protocolVersion = getIntFromUnsignedShort(buf); if (protocolVersion < MIN_SUPPORTED_VERSION || protocolVersion > MAX_SUPPORTED_VERSION) { - throw new PlatformEncDecException(MessageFormat.format("Can't decode data using protocol version {0}!", protocolVersion)); + throw new PlatformEncDecException( + MessageFormat.format("Can't decode data using protocol version {0}!", protocolVersion)); } int extensionsCount = getIntFromUnsignedShort(buf); - LOG.trace("received data for protocol id {} and version {} that contain {} extensions", protocolId, protocolVersion, - extensionsCount); + LOG.trace("received data for protocol id {} and version {} that contain {} extensions", + protocolId, protocolVersion, extensionsCount); ClientSync sync = parseExtensions(buf, protocolVersion, extensionsCount); sync.setUseConfigurationRawSchema(false); LOG.trace("Decoded binary data {}", sync); @@ -307,22 +310,9 @@ public byte[] encode(ServerSync sync) throws PlatformEncDecException { return result; } - private void buildExtensionHeader(GrowingByteBuffer buf, short extensionId, byte optionA, byte optionB, int length) { - buf.putShort(extensionId); - buf.put(optionA); - buf.put(optionB); - buf.putInt(length); - } - - private void encodeMetaData(GrowingByteBuffer buf, ServerSync sync) { - buildExtensionHeader(buf, META_DATA_EXTENSION_ID, NOTHING, NOTHING, 8); - buf.putInt(sync.getRequestId()); - buf.putInt(sync.getStatus().ordinal()); - } - private void encode(GrowingByteBuffer buf, BootstrapServerSync bootstrapSync) { buildExtensionHeader(buf, BOOTSTRAP_EXTENSION_ID, NOTHING, NOTHING, 0); - int extPosition = buf.position(); + final int extPosition = buf.position(); buf.putShort((short) bootstrapSync.getRequestId()); buf.putShort((short) bootstrapSync.getProtocolList().size()); for (ProtocolConnectionData data : bootstrapSync.getProtocolList()) { @@ -342,7 +332,7 @@ private void encode(GrowingByteBuffer buf, ProfileServerSync profileSync) { private void encode(GrowingByteBuffer buf, UserServerSync userSync) { buildExtensionHeader(buf, USER_EXTENSION_ID, NOTHING, NOTHING, 0); - int extPosition = buf.position(); + final int extPosition = buf.position(); if (userSync.getUserAttachResponse() != null) { UserAttachResponse uaResponse = userSync.getUserAttachResponse(); buf.put(USER_ATTACH_RESPONSE_FIELD_ID); @@ -351,7 +341,9 @@ private void encode(GrowingByteBuffer buf, UserServerSync userSync) { buf.put(NOTHING); if (uaResponse.getResult() != SyncStatus.SUCCESS) { - buf.putShort((short) (uaResponse.getErrorCode() != null ? uaResponse.getErrorCode().ordinal() : 0)); + buf.putShort((short) (uaResponse.getErrorCode() != null + ? uaResponse.getErrorCode().ordinal() + : 0)); if (uaResponse.getErrorReason() != null) { byte[] data = uaResponse.getErrorReason().getBytes(UTF8); buf.putShort((short) data.length); @@ -366,15 +358,15 @@ private void encode(GrowingByteBuffer buf, UserServerSync userSync) { buf.put(USER_ATTACH_NOTIFICATION_FIELD_ID); buf.put((byte) nf.getUserExternalId().length()); buf.putShort((short) nf.getEndpointAccessToken().length()); - putUTF(buf, nf.getUserExternalId()); - putUTF(buf, nf.getEndpointAccessToken()); + putUtf(buf, nf.getUserExternalId()); + putUtf(buf, nf.getEndpointAccessToken()); } if (userSync.getUserDetachNotification() != null) { UserDetachNotification nf = userSync.getUserDetachNotification(); buf.put(USER_DETACH_NOTIFICATION_FIELD_ID); buf.put(NOTHING); buf.putShort((short) nf.getEndpointAccessToken().length()); - putUTF(buf, nf.getEndpointAccessToken()); + putUtf(buf, nf.getEndpointAccessToken()); } if (userSync.getEndpointAttachResponses() != null) { buf.put(ENDPOINT_ATTACH_RESPONSE_FIELD_ID); @@ -440,7 +432,7 @@ private void encode(GrowingByteBuffer buf, ConfigurationServerSync configuration option |= 0x02; } buildExtensionHeader(buf, CONFIGURATION_EXTENSION_ID, NOTHING, (byte) option, 0); - int extPosition = buf.position(); + final int extPosition = buf.position(); if (confSchemaPresent) { buf.putInt(configurationSync.getConfSchemaBody().array().length); @@ -460,7 +452,7 @@ private void encode(GrowingByteBuffer buf, ConfigurationServerSync configuration private void encode(GrowingByteBuffer buf, NotificationServerSync notificationSync) { buildExtensionHeader(buf, NOTIFICATION_EXTENSION_ID, NOTHING, NOTHING, 0); - int extPosition = buf.position(); + final int extPosition = buf.position(); SyncResponseStatus status = notificationSync.getResponseStatus(); switch (status) { @@ -473,6 +465,8 @@ private void encode(GrowingByteBuffer buf, NotificationServerSync notificationSy case RESYNC: buf.putInt(2); break; + default: + break; } if (notificationSync.getAvailableTopics() != null) { buf.put(NF_TOPICS_FIELD_ID); @@ -483,7 +477,7 @@ private void encode(GrowingByteBuffer buf, NotificationServerSync notificationSy buf.put(t.getSubscriptionType() == SubscriptionType.MANDATORY ? MANDATORY : OPTIONAL); buf.put(NOTHING); buf.putShort((short) t.getName().getBytes(UTF8).length); - putUTF(buf, t.getName()); + putUtf(buf, t.getName()); } } if (notificationSync.getNotifications() != null) { @@ -496,9 +490,9 @@ private void encode(GrowingByteBuffer buf, NotificationServerSync notificationSy buf.put(NOTHING); buf.putShort(nf.getUid() != null ? (short) nf.getUid().length() : (short) 0); buf.putInt(nf.getBody().array().length); - long topicId = nf.getTopicId() != null ? nf.getTopicIdAsLong() : 0l; + long topicId = nf.getTopicId() != null ? nf.getTopicIdAsLong() : 0L; buf.putLong(topicId); - putUTF(buf, nf.getUid()); + putUtf(buf, nf.getUid()); put(buf, nf.getBody().array()); } } @@ -512,13 +506,14 @@ private void encode(GrowingByteBuffer buf, EventServerSync eventSync) { option = 1; } buildExtensionHeader(buf, EVENT_EXTENSION_ID, NOTHING, option, 0); - int extPosition = buf.position(); + final int extPosition = buf.position(); if (eventSync.getEventSequenceNumberResponse() != null) { buf.putInt(eventSync.getEventSequenceNumberResponse().getSeqNum()); } - if (eventSync.getEventListenersResponses() != null && !eventSync.getEventListenersResponses().isEmpty()) { + if (eventSync.getEventListenersResponses() != null + && !eventSync.getEventListenersResponses().isEmpty()) { buf.put(EVENT_LISTENERS_RESPONSE_FIELD_ID); buf.put(NOTHING); buf.putShort((short) eventSync.getEventListenersResponses().size()); @@ -540,18 +535,19 @@ private void encode(GrowingByteBuffer buf, EventServerSync eventSync) { buf.put(NOTHING); buf.putShort((short) eventSync.getEvents().size()); for (Event event : eventSync.getEvents()) { - boolean eventDataIsEmpty = event.getEventData() == null || event.getEventData().array().length == 0; + boolean eventDataIsEmpty = event.getEventData() == null + || event.getEventData().array().length == 0; if (!eventDataIsEmpty) { buf.putShort(EVENT_DATA_IS_EMPTY_OPTION); } else { buf.putShort(NOTHING); } - buf.putShort((short) event.getEventClassFQN().length()); + buf.putShort((short) event.getEventClassFqn().length()); if (!eventDataIsEmpty) { buf.putInt(event.getEventData().array().length); } buf.put(Base64Util.decode(event.getSource())); - putUTF(buf, event.getEventClassFQN()); + putUtf(buf, event.getEventClassFqn()); if (!eventDataIsEmpty) { put(buf, event.getEventData().array()); } @@ -566,7 +562,7 @@ private void encode(GrowingByteBuffer buf, RedirectServerSync redirectSync) { buf.putInt(redirectSync.getAccessPointId()); } - public void putUTF(GrowingByteBuffer buf, String str) { + public void putUtf(GrowingByteBuffer buf, String str) { if (str != null) { put(buf, str.getBytes(UTF8)); } @@ -583,19 +579,22 @@ private void put(GrowingByteBuffer buf, byte[] data) { } } - private ClientSync parseExtensions(ByteBuffer buf, int protocolVersion, int extensionsCount) throws PlatformEncDecException { + private ClientSync parseExtensions(ByteBuffer buf, int protocolVersion, int extensionsCount) + throws PlatformEncDecException { ClientSync sync = new ClientSync(); for (short extPos = 0; extPos < extensionsCount; extPos++) { if (buf.remaining() < MIN_SIZE_OF_EXTENSION_HEADER) { throw new PlatformEncDecException(MessageFormat.format( - "Extension header is to small. Available {0}, current possition is {1}!", buf.remaining(), buf.position())); + "Extension header is to small. Available {0}, current possition is {1}!", + buf.remaining(), buf.position())); } short type = buf.getShort(); int options = buf.getShort(); int payloadLength = buf.getInt(); if (buf.remaining() < payloadLength) { throw new PlatformEncDecException(MessageFormat.format( - "Extension payload is to small. Available {0}, expected {1} current possition is {2}!", buf.remaining(), + "Extension payload is to small. Available {0}, expected {1} current possition is {2}!", + buf.remaining(), payloadLength, buf.position())); } switch (type) { @@ -630,7 +629,28 @@ private ClientSync parseExtensions(ByteBuffer buf, int protocolVersion, int exte return validate(sync); } - private void parseClientSyncMetaData(ClientSync sync, ByteBuffer buf, int options, int payloadLength) throws PlatformEncDecException { + private void buildExtensionHeader(GrowingByteBuffer buf, + short extensionId, + byte optionA, + byte optionB, + int length) { + buf.putShort(extensionId); + buf.put(optionA); + buf.put(optionB); + buf.putInt(length); + } + + private void encodeMetaData(GrowingByteBuffer buf, ServerSync sync) { + buildExtensionHeader(buf, META_DATA_EXTENSION_ID, NOTHING, NOTHING, 8); + buf.putInt(sync.getRequestId()); + buf.putInt(sync.getStatus().ordinal()); + } + + private void parseClientSyncMetaData(ClientSync sync, + ByteBuffer buf, + int options, + int payloadLength) + throws PlatformEncDecException { sync.setRequestId(buf.getInt()); ClientSyncMetaData md = new ClientSyncMetaData(); if (hasOption(options, CLIENT_META_SYNC_TIMEOUT_OPTION)) { @@ -643,12 +663,15 @@ private void parseClientSyncMetaData(ClientSync sync, ByteBuffer buf, int option md.setProfileHash(getNewByteBuffer(buf, PROFILE_HASH_SIZE)); } if (hasOption(options, CLIENT_META_SYNC_SDK_TOKEN_OPTION)) { - md.setSdkToken(getUTF8String(buf, Constants.SDK_TOKEN_SIZE)); + md.setSdkToken(getUtf8String(buf, Constants.SDK_TOKEN_SIZE)); } sync.setClientSyncMetaData(md); } - private void parseBootstrapClientSync(ClientSync sync, ByteBuffer buf, int options, int payloadLength) { + private void parseBootstrapClientSync(ClientSync sync, + ByteBuffer buf, + int options, + int payloadLength) { int requestId = buf.getShort(); int protocolCount = buf.getShort(); List keys = new ArrayList<>(protocolCount); @@ -660,7 +683,10 @@ private void parseBootstrapClientSync(ClientSync sync, ByteBuffer buf, int optio sync.setBootstrapSync(new BootstrapClientSync(requestId, keys)); } - private void parseProfileClientSync(ClientSync sync, ByteBuffer buf, int options, int payloadLength) { + private void parseProfileClientSync(ClientSync sync, + ByteBuffer buf, + int options, + int payloadLength) { int payloadLimitPosition = buf.position() + payloadLength; ProfileClientSync profileSync = new ProfileClientSync(); profileSync.setProfileBody(getNewByteBuffer(buf, buf.getInt())); @@ -673,7 +699,7 @@ private void parseProfileClientSync(ClientSync sync, ByteBuffer buf, int options profileSync.setEndpointPublicKey(getNewByteBuffer(buf, getIntFromUnsignedShort(buf))); break; case ACCESS_TOKEN_FIELD_ID: - profileSync.setEndpointAccessToken(getUTF8String(buf)); + profileSync.setEndpointAccessToken(getUtf8String(buf)); break; default: break; @@ -682,7 +708,10 @@ private void parseProfileClientSync(ClientSync sync, ByteBuffer buf, int options sync.setProfileSync(profileSync); } - private void parseUserClientSync(ClientSync sync, ByteBuffer buf, int options, int payloadLength) { + private void parseUserClientSync(ClientSync sync, + ByteBuffer buf, + int options, + int payloadLength) { int payloadLimitPosition = buf.position() + payloadLength; UserClientSync userSync = new UserClientSync(); while (buf.position() < payloadLimitPosition) { @@ -704,7 +733,10 @@ private void parseUserClientSync(ClientSync sync, ByteBuffer buf, int options, i sync.setUserSync(userSync); } - private void parseLogClientSync(ClientSync sync, ByteBuffer buf, int options, int payloadLength) { + private void parseLogClientSync(ClientSync sync, + ByteBuffer buf, + int options, + int payloadLength) { LogClientSync logSync = new LogClientSync(); logSync.setRequestId(getIntFromUnsignedShort(buf)); int size = getIntFromUnsignedShort(buf); @@ -716,7 +748,10 @@ private void parseLogClientSync(ClientSync sync, ByteBuffer buf, int options, in sync.setLogSync(logSync); } - private void parseConfigurationClientSync(ClientSync sync, ByteBuffer buf, int options, int payloadLength) { + private void parseConfigurationClientSync(ClientSync sync, + ByteBuffer buf, + int options, + int payloadLength) { ConfigurationClientSync confSync = new ConfigurationClientSync(); if (hasOption(options, CONFIGURATION_HASH_OPTION)) { confSync.setConfigurationHash(getNewByteBuffer(buf, CONFIGURATION_HASH_SIZE)); @@ -727,7 +762,10 @@ private void parseConfigurationClientSync(ClientSync sync, ByteBuffer buf, int o sync.setConfigurationSync(confSync); } - private void parseEventClientSync(ClientSync sync, ByteBuffer buf, int options, int payloadLength) { + private void parseEventClientSync(ClientSync sync, + ByteBuffer buf, + int options, + int payloadLength) { EventClientSync eventSync = new EventClientSync(); if (hasOption(options, EVENT_SEQ_NUMBER_REQUEST_OPTION)) { eventSync.setSeqNumberRequest(true); @@ -751,7 +789,10 @@ private void parseEventClientSync(ClientSync sync, ByteBuffer buf, int options, sync.setEventSync(eventSync); } - private void parseNotificationClientSync(ClientSync sync, ByteBuffer buf, int options, int payloadLength) { + private void parseNotificationClientSync(ClientSync sync, + ByteBuffer buf, + int options, + int payloadLength) { int payloadLimitPosition = buf.position() + payloadLength; NotificationClientSync nfSync = new NotificationClientSync(); @@ -773,18 +814,24 @@ private void parseNotificationClientSync(ClientSync sync, ByteBuffer buf, int op case NF_SUBSCRIPTION_REMOVE_FIELD_ID: parseSubscriptionCommands(nfSync, buf, false); break; + default: + break; } } sync.setNotificationSync(nfSync); } - private void parseSubscriptionCommands(NotificationClientSync nfSync, ByteBuffer buf, boolean add) { + private void parseSubscriptionCommands(NotificationClientSync nfSync, + ByteBuffer buf, + boolean add) { int count = getIntFromUnsignedShort(buf); if (nfSync.getSubscriptionCommands() == null) { - nfSync.setSubscriptionCommands(new ArrayList()); + nfSync.setSubscriptionCommands(new ArrayList<>()); } - SubscriptionCommandType subscriptionType = add ? SubscriptionCommandType.ADD : SubscriptionCommandType.REMOVE; - List commands = new ArrayList(); + SubscriptionCommandType subscriptionType = add + ? SubscriptionCommandType.ADD + : SubscriptionCommandType.REMOVE; + List commands = new ArrayList<>(); for (int i = 0; i < count; i++) { long topicId = buf.getLong(); commands.add(new SubscriptionCommand(topicId, subscriptionType)); @@ -808,7 +855,7 @@ private List parseUnicastIds(ByteBuffer buf) { List uids = new ArrayList<>(count); for (int i = 0; i < count; i++) { int uidLength = buf.getInt(); - uids.add(getUTF8String(buf, uidLength)); + uids.add(getUtf8String(buf, uidLength)); } return uids; } @@ -824,7 +871,7 @@ private List parseListenerRequests(ByteBuffer buf) { int fqnLength = getIntFromUnsignedShort(buf); // reserved buf.getShort(); - fqns.add(getUTF8String(buf, fqnLength)); + fqns.add(getUtf8String(buf, fqnLength)); } requests.add(new EventListenersRequest(requestId, fqns)); } @@ -846,7 +893,7 @@ private List parseEvents(ByteBuffer buf) { if (hasOption(eventOptions, 0x01)) { event.setTarget(Base64Util.encode(getNewByteArray(buf, PUBLIC_KEY_HASH_SIZE))); } - event.setEventClassFQN(getUTF8String(buf, fqnLength)); + event.setEventClassFqn(getUtf8String(buf, fqnLength)); if (dataSize > 0) { event.setEventData(getNewByteBuffer(buf, dataSize)); } else { @@ -864,7 +911,7 @@ private List parseEndpointAttachRequests(ByteBuffer buf) List requests = new ArrayList(count); for (int i = 0; i < count; i++) { int requestId = getIntFromUnsignedShort(buf); - String accessToken = getUTF8String(buf); + String accessToken = getUtf8String(buf); requests.add(new EndpointAttachRequest(requestId, accessToken)); } return requests; @@ -879,7 +926,8 @@ private List parseEndpointDetachRequests(ByteBuffer buf) int requestId = getIntFromUnsignedShort(buf); // reserved buf.getShort(); - requests.add(new EndpointDetachRequest(requestId, Base64Util.encode(getNewByteArray(buf, PUBLIC_KEY_HASH_SIZE)))); + requests.add(new EndpointDetachRequest( + requestId, Base64Util.encode(getNewByteArray(buf, PUBLIC_KEY_HASH_SIZE)))); } return requests; } @@ -890,15 +938,16 @@ private UserAttachRequest parseUserAttachRequest(ByteBuffer buf) { int verifierTokenLength = getIntFromUnsignedShort(buf); // reserved buf.getShort(); - String userExternalId = getUTF8String(buf, extIdLength); - String userAccessToken = getUTF8String(buf, tokenLength); - String userVerifierToken = getUTF8String(buf, verifierTokenLength); + String userExternalId = getUtf8String(buf, extIdLength); + String userAccessToken = getUtf8String(buf, tokenLength); + String userVerifierToken = getUtf8String(buf, verifierTokenLength); return new UserAttachRequest(userVerifierToken, userExternalId, userAccessToken); } private ClientSync validate(ClientSync sync) throws PlatformEncDecException { if (sync.getClientSyncMetaData() == null) { - throw new PlatformEncDecException(MessageFormat.format("Input data does not have client sync meta data: {0}!", sync)); + throw new PlatformEncDecException( + MessageFormat.format("Input data does not have client sync meta data: {0}!", sync)); } return sync; } diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/GrowingByteBuffer.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/GrowingByteBuffer.java index 2b713fb487..3c20bbeb61 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/GrowingByteBuffer.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/GrowingByteBuffer.java @@ -39,9 +39,9 @@ public GrowingByteBuffer(int size) { data = ByteBuffer.wrap(new byte[size]); } - public GrowingByteBuffer put(byte b) { + public GrowingByteBuffer put(byte bt) { resizeIfNeeded(SIZE_OF_BYTE); - data.put(b); + data.put(bt); return this; } @@ -51,32 +51,32 @@ public GrowingByteBuffer put(byte[] bytes) { return this; } - public GrowingByteBuffer putShort(short s) { + public GrowingByteBuffer putShort(short shrt) { resizeIfNeeded(SIZE_OF_SHORT); - data.putShort(s); + data.putShort(shrt); return this; } - public GrowingByteBuffer putShort(int position, short s) { + public GrowingByteBuffer putShort(int position, short shrt) { checkPosition(position + SIZE_OF_SHORT); int tmp = data.position(); data.position(position); - data.putShort(s); + data.putShort(shrt); data.position(tmp); return this; } - public GrowingByteBuffer putInt(int i) { + public GrowingByteBuffer putInt(int integer) { resizeIfNeeded(SIZE_OF_INT); - data.putInt(i); + data.putInt(integer); return this; } - public GrowingByteBuffer putInt(int position, int i) { + public GrowingByteBuffer putInt(int position, int integer) { checkPosition(position + SIZE_OF_INT); int tmp = data.position(); data.position(position); - data.putInt(i); + data.putInt(integer); data.position(tmp); return this; } @@ -93,14 +93,17 @@ public int position() { private void checkPosition(int position) { if (data.capacity() < position) { - throw new IllegalArgumentException(MessageFormat.format("Position {0} is greater then capacity {1}", position, data.capacity())); + throw new IllegalArgumentException( + MessageFormat.format("Position {0} is greater then capacity {1}", + position, data.capacity())); } } private void resizeIfNeeded(int size) { if (size > data.remaining()) { int position = data.position(); - data = ByteBuffer.wrap(Arrays.copyOf(data.array(), Math.max(data.position() + size, data.array().length * 2))); + data = ByteBuffer.wrap(Arrays.copyOf( + data.array(), Math.max(data.position() + size, data.array().length * 2))); data.position(position); } } diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/PlatformEncDec.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/PlatformEncDec.java index b4e47f214a..061c753d01 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/PlatformEncDec.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/PlatformEncDec.java @@ -26,7 +26,7 @@ public interface PlatformEncDec { /** - * Returns id of the platform level protocol + * Returns id of the platform level protocol. */ int getId(); diff --git a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/PlatformLookup.java b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/PlatformLookup.java index 201e9120e7..72efe3aff1 100644 --- a/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/PlatformLookup.java +++ b/server/common/server-shared/src/main/java/org/kaaproject/kaa/server/sync/platform/PlatformLookup.java @@ -28,7 +28,7 @@ import java.util.Set; /** - * Provides ability to lookup and init {@link PlatformEncDec} instances + * Provides ability to lookup and init {@link PlatformEncDec} instances. * * @author Andrew Shvayka */ @@ -43,9 +43,10 @@ private PlatformLookup() { } public static Set lookupPlatformProtocols(String... packageNames) { - ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false); + ClassPathScanningCandidateComponentProvider scanner = + new ClassPathScanningCandidateComponentProvider(false); scanner.addIncludeFilter(new AnnotationTypeFilter(KaaPlatformProtocol.class)); - Set beans = new HashSet(); + Set beans = new HashSet<>(); for (String packageName : packageNames) { beans.addAll(scanner.findCandidateComponents(packageName)); } @@ -56,7 +57,8 @@ public static Set lookupPlatformProtocols(String... packageNames) { return protocols; } - public static Map initPlatformProtocolMap(Set platformProtocols) { + public static Map initPlatformProtocolMap( + Set platformProtocols) { Map platformEncDecMap = new HashMap<>(); for (String platformProtocol : platformProtocols) { try { @@ -64,8 +66,8 @@ public static Map initPlatformProtocolMap(Set p PlatformEncDec protocol = (PlatformEncDec) clazz.newInstance(); platformEncDecMap.put(protocol.getId(), protocol); LOG.info("Successfully initialized platform protocol {}", platformProtocol); - } catch (ReflectiveOperationException e) { - LOG.error("Error during instantiation of platform protocol", e); + } catch (ReflectiveOperationException exception) { + LOG.error("Error during instantiation of platform protocol", exception); } } return platformEncDecMap; diff --git a/server/common/server-shared/src/test/java/org/kaaproject/kaa/server/sync/platform/AvroEncDecTest.java b/server/common/server-shared/src/test/java/org/kaaproject/kaa/server/sync/platform/AvroEncDecTest.java index d2efd919be..b5e63d92bd 100644 --- a/server/common/server-shared/src/test/java/org/kaaproject/kaa/server/sync/platform/AvroEncDecTest.java +++ b/server/common/server-shared/src/test/java/org/kaaproject/kaa/server/sync/platform/AvroEncDecTest.java @@ -94,7 +94,7 @@ public void convertNullTest() { @Test public void convertEventTest() { Event event = new Event(); - org.kaaproject.kaa.common.endpoint.gen.Event genEvent = new org.kaaproject.kaa.common.endpoint.gen.Event(event.getSeqNum(), event.getEventClassFQN(), event.getEventData(), event.getSource(), event.getTarget()); + org.kaaproject.kaa.common.endpoint.gen.Event genEvent = new org.kaaproject.kaa.common.endpoint.gen.Event(event.getSeqNum(), event.getEventClassFqn(), event.getEventData(), event.getSource(), event.getTarget()); org.kaaproject.kaa.common.endpoint.gen.Event nullGenEvent = null; Assert.assertEquals(event, AvroEncDec.convert(genEvent)); Assert.assertNull(AvroEncDec.convert(nullGenEvent)); diff --git a/server/common/server-shared/src/test/java/org/kaaproject/kaa/server/sync/platform/BinaryEncDecTest.java b/server/common/server-shared/src/test/java/org/kaaproject/kaa/server/sync/platform/BinaryEncDecTest.java index 472cffcb7f..3d47a0eaac 100644 --- a/server/common/server-shared/src/test/java/org/kaaproject/kaa/server/sync/platform/BinaryEncDecTest.java +++ b/server/common/server-shared/src/test/java/org/kaaproject/kaa/server/sync/platform/BinaryEncDecTest.java @@ -207,7 +207,7 @@ public void testEncodeEventServerSync() throws PlatformEncDecException { EventServerSync eSync = new EventServerSync(); eSync.setEventSequenceNumberResponse(new EventSequenceNumberResponse(MAGIC_NUMBER)); Event event = new Event(); - event.setEventClassFQN("fqn"); + event.setEventClassFqn("fqn"); event.setSource(Base64Util.encode(new byte[SHA_1_LENGTH])); eSync.setEvents(Collections.singletonList(event)); sync.setEventSync(eSync); @@ -499,12 +499,12 @@ public void testEventClientSync() throws PlatformEncDecException { Assert.assertNotNull(eSync.getEventListenersRequests()); Assert.assertEquals(1, eSync.getEventListenersRequests().size()); Assert.assertEquals(MAGIC_NUMBER, eSync.getEventListenersRequests().get(0).getRequestId()); - Assert.assertNotNull(eSync.getEventListenersRequests().get(0).getEventClassFQNs()); - Assert.assertEquals("name", eSync.getEventListenersRequests().get(0).getEventClassFQNs().get(0)); + Assert.assertNotNull(eSync.getEventListenersRequests().get(0).getEventClassFqns()); + Assert.assertEquals("name", eSync.getEventListenersRequests().get(0).getEventClassFqns().get(0)); Assert.assertNotNull(eSync.getEvents()); Assert.assertEquals(1, eSync.getEvents().size()); Assert.assertEquals(MAGIC_NUMBER, eSync.getEvents().get(0).getSeqNum()); - Assert.assertEquals("name", eSync.getEvents().get(0).getEventClassFQN()); + Assert.assertEquals("name", eSync.getEvents().get(0).getEventClassFqn()); Assert.assertEquals(Base64Util.encode(hash), eSync.getEvents().get(0).getTarget()); Assert.assertEquals(MAGIC_NUMBER, eSync.getEvents().get(0).getEventData().array()[MAGIC_INDEX]); } diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/AbstractKaaTransport.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/AbstractKaaTransport.java index c6ade318c5..f43aad58b4 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/AbstractKaaTransport.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/AbstractKaaTransport.java @@ -43,7 +43,7 @@ public abstract class AbstractKaaTransport impleme private static final Logger LOG = LoggerFactory.getLogger(AbstractKaaTransport.class); private static final Charset UTF8 = Charset.forName("UTF-8"); /** - * A message handler + * A message handler. */ protected MessageHandler handler; @@ -64,12 +64,20 @@ public void init(GenericTransportContext context) throws TransportLifecycleExcep this.context = new SpecificTransportContext(context, config); init(this.context); LOG.info("Transport {} initialized with {}", getClassName(), this.context.getConfiguration()); - } catch (IOException e) { - LOG.error(MessageFormat.format("Failed to initialize transport {0}", getClassName()), e); - throw new TransportLifecycleException(e); + } catch (IOException exception) { + LOG.error(MessageFormat.format("Failed to initialize transport {0}", getClassName()), exception); + throw new TransportLifecycleException(exception); } } + /** + * Initializes the transport with specified context. + * + * @param context the initialization context + */ + protected abstract void init(SpecificTransportContext context) + throws TransportLifecycleException; + @Override public TransportMetaData getConnectionInfo() { LOG.info("Serializing connection info"); @@ -80,13 +88,6 @@ public TransportMetaData getConnectionInfo() { return new TransportMetaData(getMinSupportedVersion(), getMaxSupportedVersion(), buffs); } - /** - * Initializes the transport with specified context. - * - * @param context the initialization context - */ - protected abstract void init(SpecificTransportContext context) throws TransportLifecycleException; - /** * Gets the configuration class. * @@ -108,7 +109,7 @@ protected String replaceProperty(String source, String propertyName, String prop return source.replace("${" + propertyName + "}", propertyValue); } - protected byte[] toUTF8Bytes(String str) { + protected byte[] toUtf8Bytes(String str) { return str.getBytes(UTF8); } } diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/AbstractTransportService.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/AbstractTransportService.java index c680abb25b..dcf989da7a 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/AbstractTransportService.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/AbstractTransportService.java @@ -50,7 +50,8 @@ * @author Andrew Shvayka */ public abstract class AbstractTransportService implements TransportService { - protected static final String TRANSPORT_CONFIGURATION_SCAN_PACKAGE = "org.kaaproject.kaa.server.transport"; + protected static final String TRANSPORT_CONFIGURATION_SCAN_PACKAGE = + "org.kaaproject.kaa.server.transport"; /** * The Constant LOG. @@ -68,15 +69,18 @@ public AbstractTransportService() { this.listeners = new HashSet(); } - private static List toTransportMDList(Map transportMap) { - List mdList = new ArrayList<>(transportMap.size()); + private static List toTransportMdList( + Map transportMap) { + List mdList = + new ArrayList<>(transportMap.size()); for (Entry entry : transportMap.entrySet()) { TransportMetaData source = entry.getValue().getConnectionInfo(); - org.kaaproject.kaa.server.common.zk.gen.TransportMetaData md = new org.kaaproject.kaa.server.common.zk.gen.TransportMetaData(); + org.kaaproject.kaa.server.common.zk.gen.TransportMetaData md = + new org.kaaproject.kaa.server.common.zk.gen.TransportMetaData(); md.setId(entry.getKey()); md.setMinSupportedVersion(source.getMinSupportedVersion()); md.setMaxSupportedVersion(source.getMaxSupportedVersion()); - List connectionInfoList = new ArrayList(); + List connectionInfoList = new ArrayList<>(); for (int i = md.getMinSupportedVersion(); i <= md.getMaxSupportedVersion(); i++) { for (byte[] connectionInfo : source.getConnectionInfoList(i)) { connectionInfoList.add(new VersionConnectionInfoPair(i, ByteBuffer.wrap(connectionInfo))); @@ -90,44 +94,55 @@ private static List t @Override public void lookupAndInit() { - LOG.info("Lookup of available transport configurations started in package {}.", TRANSPORT_CONFIGURATION_SCAN_PACKAGE); + LOG.info("Lookup of available transport configurations started in package {}.", + TRANSPORT_CONFIGURATION_SCAN_PACKAGE); configs.clear(); transports.clear(); - ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false); + ClassPathScanningCandidateComponentProvider scanner = + new ClassPathScanningCandidateComponentProvider(false); scanner.addIncludeFilter(new AnnotationTypeFilter(KaaTransportConfig.class)); - Set beans = scanner.findCandidateComponents(TRANSPORT_CONFIGURATION_SCAN_PACKAGE); + Set beans = scanner.findCandidateComponents( + TRANSPORT_CONFIGURATION_SCAN_PACKAGE); for (BeanDefinition bean : beans) { LOG.info("Found transport configuration {}", bean.getBeanClassName()); try { Class clazz = Class.forName(bean.getBeanClassName()); TransportConfig transportConfig = (TransportConfig) clazz.newInstance(); configs.put(transportConfig.getId(), transportConfig); - } catch (ReflectiveOperationException e) { - LOG.error(MessageFormat.format("Failed to init transport configuration for {0}", bean.getBeanClassName()), e); + } catch (ReflectiveOperationException exception) { + LOG.error(MessageFormat.format("Failed to init transport configuration for {0}", + bean.getBeanClassName()), exception); } } - LOG.info("Lookup of available transport configurations found {} configurations.", configs.size()); + LOG.info("Lookup of available transport configurations found {} configurations.", + configs.size()); LOG.info("Lookup of transport properties started"); TransportProperties transportProperties = new TransportProperties(getServiceProperties()); LOG.info("Lookup of transport properties found {} properties", transportProperties.size()); for (TransportConfig config : configs.values()) { - LOG.info("Initializing transport with name {} and class {}", config.getName(), config.getTransportClass()); + LOG.info("Initializing transport with name {} and class {}", + config.getName(), config.getTransportClass()); try { Class clazz = Class.forName(config.getTransportClass()); Transport transport = (Transport) clazz.newInstance(); String transportConfigFile = getTransportConfigPrefix() + "-" + config.getConfigFileName(); LOG.info("Lookup of transport configuration file {}", transportConfigFile); - URL configFileURL = this.getClass().getClassLoader().getResource(transportConfigFile); - GenericAvroConverter configConverter = new GenericAvroConverter(config.getConfigSchema()); - GenericRecord configRecord = configConverter.decodeJson(Files.readAllBytes(Paths.get(configFileURL.toURI()))); + URL configFileUrl = this.getClass().getClassLoader().getResource(transportConfigFile); + GenericAvroConverter configConverter = + new GenericAvroConverter<>(config.getConfigSchema()); + GenericRecord configRecord = configConverter.decodeJson( + Files.readAllBytes(Paths.get(configFileUrl.toURI()))); LOG.info("Lookup of transport configuration file {}", transportConfigFile); - TransportContext context = new TransportContext(transportProperties, getPublicKey(), getMessageHandler()); + TransportContext context = new TransportContext( + transportProperties, getPublicKey(), getMessageHandler()); transport.init(new GenericTransportContext(context, configConverter.encode(configRecord))); transports.put(config.getId(), transport); - } catch (ReflectiveOperationException | IOException | URISyntaxException | TransportLifecycleException e) { - LOG.error(MessageFormat.format("Failed to init transport for {0}", config.getTransportClass()), e); + } catch (ReflectiveOperationException | IOException + | URISyntaxException | TransportLifecycleException exception) { + LOG.error(MessageFormat.format("Failed to init transport for {0}", + config.getTransportClass()), exception); } } } @@ -174,7 +189,8 @@ public boolean removeListener(TransportUpdateListener listener) { ; private void notifyListeners() { - List mdList = toTransportMDList(transports); + List mdList = toTransportMdList( + transports); for (TransportUpdateListener listener : listeners) { listener.onTransportsStarted(mdList); } diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/EndpointRevocationException.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/EndpointRevocationException.java index 18e3be5f35..dff62aa07a 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/EndpointRevocationException.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/EndpointRevocationException.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.kaaproject.kaa.server.transport; /** diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/EndpointVerificationError.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/EndpointVerificationError.java index f95dee442d..b33f1029fe 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/EndpointVerificationError.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/EndpointVerificationError.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.kaaproject.kaa.server.transport; public enum EndpointVerificationError { diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/EndpointVerificationException.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/EndpointVerificationException.java index e1c85f897a..1464942f56 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/EndpointVerificationException.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/EndpointVerificationException.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.kaaproject.kaa.server.transport; /** diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/InvalidSDKTokenException.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/InvalidSdkTokenException.java similarity index 80% rename from server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/InvalidSDKTokenException.java rename to server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/InvalidSdkTokenException.java index aeecb0e193..d86152ee4d 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/InvalidSDKTokenException.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/InvalidSdkTokenException.java @@ -18,9 +18,9 @@ /** * Class that represents exception that is thrown when client makes request - * and uses invalid SDK token + * and uses invalid SDK token. */ -public class InvalidSDKTokenException extends Exception { +public class InvalidSdkTokenException extends Exception { /** * The Constant serialVersionUID. @@ -28,11 +28,9 @@ public class InvalidSDKTokenException extends Exception { private static final long serialVersionUID = -6241500436883054355L; /** - * Instantiates a new invalid sdk token exception - * - * @param message the message + * Instantiates a new invalid sdk token exception. */ - public InvalidSDKTokenException() { + public InvalidSdkTokenException() { super(); } } diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/TransportMetaData.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/TransportMetaData.java index e5dec353d0..60c276882f 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/TransportMetaData.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/TransportMetaData.java @@ -31,7 +31,7 @@ public class TransportMetaData implements Serializable { /** - * Generated value + * Generated value. */ private static final long serialVersionUID = 9208273898021695583L; @@ -40,7 +40,9 @@ public class TransportMetaData implements Serializable { private final List defaultConnectionInfoList; private final Map> versionSpecificConnectionInfoList; - public TransportMetaData(int minSupportedVersion, int maxSupportedVersion, List defaultConnectionInfoList) { + public TransportMetaData(int minSupportedVersion, + int maxSupportedVersion, + List defaultConnectionInfoList) { super(); this.minSupportedVersion = minSupportedVersion; this.maxSupportedVersion = maxSupportedVersion; diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/TransportProperties.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/TransportProperties.java index 8cc2a29c46..35daf0608e 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/TransportProperties.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/TransportProperties.java @@ -27,9 +27,6 @@ */ public class TransportProperties extends Properties { - /** - * - */ private static final long serialVersionUID = -3398931583634951967L; private static final String FILTER_PREFIX = "transport_"; diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/TransportService.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/TransportService.java index 4f81488b17..a37b343c8c 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/TransportService.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/TransportService.java @@ -18,14 +18,14 @@ /** * Responsible for lookup, initialization and life-cycle management of the - * available transport implementations + * available transport implementations. * * @author Andrew Shvayka */ public interface TransportService { /** - * Look up the available transport implementations and initialize them + * Look up the available transport implementations and initialize them. */ void lookupAndInit(); @@ -40,12 +40,12 @@ public interface TransportService { void stop(); /** - * Adds a listener for the {@link Transport} state updates + * Adds a listener for the {@link Transport} state updates. */ boolean addListener(TransportUpdateListener listener); /** - * Removes the {@link Transport} state updates listener + * Removes the {@link Transport} state updates listener. */ boolean removeListener(TransportUpdateListener listener); diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/TransportUpdateListener.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/TransportUpdateListener.java index 0d3af3f64a..6ea91646c5 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/TransportUpdateListener.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/TransportUpdateListener.java @@ -30,7 +30,7 @@ public interface TransportUpdateListener { /** * Notify about the initialized transports. * - * @param msList a list of the initialized transport meta data + * @param mdList a list of the initialized transport meta data */ void onTransportsStarted(List mdList); diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/channel/ChannelContext.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/channel/ChannelContext.java index c4c4c55127..4780932383 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/channel/ChannelContext.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/channel/ChannelContext.java @@ -25,30 +25,30 @@ public interface ChannelContext { /** - * Writes and flushes the given object + * Writes and flushes the given object. * * @param response the object to write */ void writeAndFlush(Object response); /** - * Writes the given object but doesn't flush it + * Writes the given object but doesn't flush it. * * @param object the object to write */ void write(Object object); /** - * Sends the flush command to the given channel + * Sends the flush command to the given channel. */ void flush(); /** * Notifies the channel context about exceptions related to message - * processing for this channel + * processing for this channel. * - * @param e the caught exception + * @param exception the caught exception */ - void fireExceptionCaught(Exception e); + void fireExceptionCaught(Exception exception); } diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/AbstractMessage.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/AbstractMessage.java index 8fc6ec6f77..31d27d51d6 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/AbstractMessage.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/AbstractMessage.java @@ -37,8 +37,12 @@ public abstract class AbstractMessage implements PlatformAware { private final MessageBuilder responseConverter; private final ErrorBuilder errorConverter; - protected AbstractMessage(UUID uuid, Integer platformId, ChannelContext channelContext, ChannelType channelType, - MessageBuilder responseConverter, ErrorBuilder errorConverter) { + protected AbstractMessage(UUID uuid, + Integer platformId, + ChannelContext channelContext, + ChannelType channelType, + MessageBuilder responseConverter, + ErrorBuilder errorConverter) { super(); this.uuid = uuid; this.platformId = platformId; diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/ErrorBuilder.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/ErrorBuilder.java index 0e8647cb30..24817e3904 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/ErrorBuilder.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/ErrorBuilder.java @@ -28,8 +28,8 @@ public interface ErrorBuilder { * Convert the exception into objects specific to the corresponding * transport channel. * - * @param e the exception to convert + * @param exception the exception to convert * @return result the result of conversion */ - Object[] build(Exception e); + Object[] build(Exception exception); } diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/Message.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/Message.java index 5c5c8658a5..78505207f6 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/Message.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/Message.java @@ -35,7 +35,7 @@ public interface Message extends ChannelAware, PlatformAware { MessageBuilder getMessageBuilder(); /** - * Returns the error builder + * Returns the error builder. * * @return the error builder */ diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/SessionAwareMessage.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/SessionAwareMessage.java index da337ba492..c33f6caa12 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/SessionAwareMessage.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/SessionAwareMessage.java @@ -19,7 +19,7 @@ import org.kaaproject.kaa.server.transport.session.SessionAware; /** - * Represents {@link SessionAware} {@link Message} + * Represents {@link SessionAware} {@link Message}. * * @author Andrew Shvayka */ diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/SessionInitMessage.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/SessionInitMessage.java index 53f32be3b1..a2446e5021 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/SessionInitMessage.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/message/SessionInitMessage.java @@ -47,7 +47,7 @@ public interface SessionInitMessage extends Message, SessionCreateListener { byte[] getSessionKeySignature(); /** - * Returns a keep alive interval for this session + * Returns a keep alive interval for this session. * * @return a keep alive interval */ diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/platform/PlatformAware.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/platform/PlatformAware.java index acb7b29347..eed1ed658b 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/platform/PlatformAware.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/platform/PlatformAware.java @@ -25,7 +25,7 @@ public interface PlatformAware { /** - * Returns the platform layer id + * Returns the platform layer id. * * @return the platform layer id */ diff --git a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/session/SessionInfo.java b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/session/SessionInfo.java index 58bb6b9f04..c06a5f3f07 100644 --- a/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/session/SessionInfo.java +++ b/server/common/transport-shared/src/main/java/org/kaaproject/kaa/server/transport/session/SessionInfo.java @@ -41,8 +41,10 @@ public final class SessionInfo implements PlatformAware { private final int keepAlive; private final boolean isEncrypted; - public SessionInfo(UUID uuid, int platformId, ChannelContext ctx, ChannelType channelType, CipherPair cipherPair, EndpointObjectHash key, - String applicationToken, String sdkToken, int keepAlive, boolean isEncrypted) { + public SessionInfo(UUID uuid, int platformId, ChannelContext ctx, ChannelType channelType, + CipherPair cipherPair, EndpointObjectHash key, + String applicationToken, String sdkToken, + int keepAlive, boolean isEncrypted) { super(); this.uuid = uuid; this.platformId = platformId; diff --git a/server/common/utils/src/main/java/org/kaaproject/kaa/server/common/utils/CRC32Util.java b/server/common/utils/src/main/java/org/kaaproject/kaa/server/common/utils/Crc32Util.java similarity index 93% rename from server/common/utils/src/main/java/org/kaaproject/kaa/server/common/utils/CRC32Util.java rename to server/common/utils/src/main/java/org/kaaproject/kaa/server/common/utils/Crc32Util.java index 67da093f77..9d69815e04 100644 --- a/server/common/utils/src/main/java/org/kaaproject/kaa/server/common/utils/CRC32Util.java +++ b/server/common/utils/src/main/java/org/kaaproject/kaa/server/common/utils/Crc32Util.java @@ -20,15 +20,15 @@ import java.util.zip.CRC32; /** - * An util class that provides convenient methods to get crc32 checksum from {@link String} + * An util class that provides convenient methods to get crc32 checksum from {@link String}. * * @author Andrew Shvayka */ -public class CRC32Util { +public class Crc32Util { private static final Charset UTF8 = Charset.forName("UTF-8"); - private CRC32Util() { + private Crc32Util() { } /** diff --git a/server/common/utils/src/main/java/org/kaaproject/kaa/server/common/utils/FileUtils.java b/server/common/utils/src/main/java/org/kaaproject/kaa/server/common/utils/FileUtils.java index b35d1819c1..066c24bb49 100644 --- a/server/common/utils/src/main/java/org/kaaproject/kaa/server/common/utils/FileUtils.java +++ b/server/common/utils/src/main/java/org/kaaproject/kaa/server/common/utils/FileUtils.java @@ -44,7 +44,8 @@ public static String readResource(String resource) throws IOException { String result = null; try { StringBuffer fileData = new StringBuffer(); - InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource); + InputStream input = Thread.currentThread().getContextClassLoader() + .getResourceAsStream(resource); BufferedReader reader = new BufferedReader(new InputStreamReader(input)); char[] buf = new char[1024]; int numRead = 0; @@ -54,10 +55,10 @@ public static String readResource(String resource) throws IOException { } reader.close(); result = fileData.toString(); - } catch (IOException e) { + } catch (IOException exception) { LOG.error("Unable to read from specified resource '" - + resource + "'! Error: " + e.getMessage(), e); - throw e; + + resource + "'! Error: " + exception.getMessage(), exception); + throw exception; } return result; } @@ -70,12 +71,13 @@ public static String readResource(String resource) throws IOException { * @throws IOException Signals that an I/O exception has occurred. */ public static byte[] readResourceBytes(String resource) throws IOException { - try (InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) { + try (InputStream input = Thread.currentThread().getContextClassLoader() + .getResourceAsStream(resource)) { return IOUtils.toByteArray(input); - } catch (IOException e) { + } catch (IOException exception) { LOG.error("Unable to read from specified resource '" - + resource + "'! Error: " + e.getMessage(), e); - throw e; + + resource + "'! Error: " + exception.getMessage(), exception); + throw exception; } } @@ -89,14 +91,15 @@ public static byte[] readResourceBytes(String resource) throws IOException { public static Properties readResourceProperties(String resource) throws IOException { Properties result = null; try { - InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource); + InputStream input = Thread.currentThread().getContextClassLoader() + .getResourceAsStream(resource); result = new Properties(); result.load(input); input.close(); - } catch (IOException e) { + } catch (IOException exception) { LOG.error("Unable to read from specified resource '" - + resource + "'! Error: " + e.getMessage(), e); - throw e; + + resource + "'! Error: " + exception.getMessage(), exception); + throw exception; } return result; } diff --git a/server/common/utils/src/main/java/org/kaaproject/kaa/server/common/utils/KaaUncaughtExceptionHandler.java b/server/common/utils/src/main/java/org/kaaproject/kaa/server/common/utils/KaaUncaughtExceptionHandler.java index 334d29375d..3dc7bb1ce5 100644 --- a/server/common/utils/src/main/java/org/kaaproject/kaa/server/common/utils/KaaUncaughtExceptionHandler.java +++ b/server/common/utils/src/main/java/org/kaaproject/kaa/server/common/utils/KaaUncaughtExceptionHandler.java @@ -21,7 +21,7 @@ /** * An KaaUncaughtExceptionHandler class provides method to handle exceptions - * in that threads which don't contain own exceptoin handler + * in that threads which don't contain own exceptoin handler. * * @author Oleksandr Didukh */ @@ -34,6 +34,7 @@ public class KaaUncaughtExceptionHandler implements Thread.UncaughtExceptionHand @Override public void uncaughtException(Thread thread, Throwable exception) { - LOG.error("Thread [name: {}, id: {}] uncaught exception: ", thread.getName(), thread.getId(), exception); + LOG.error("Thread [name: {}, id: {}] uncaught exception: ", + thread.getName(), thread.getId(), exception); } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/akka/actors/io/EncDecActorMessageProcessor.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/akka/actors/io/EncDecActorMessageProcessor.java index 25484b2f2a..aadb3f0263 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/akka/actors/io/EncDecActorMessageProcessor.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/akka/actors/io/EncDecActorMessageProcessor.java @@ -49,7 +49,7 @@ import org.kaaproject.kaa.server.sync.platform.PlatformLookup; import org.kaaproject.kaa.server.transport.EndpointVerificationError; import org.kaaproject.kaa.server.transport.EndpointVerificationException; -import org.kaaproject.kaa.server.transport.InvalidSDKTokenException; +import org.kaaproject.kaa.server.transport.InvalidSdkTokenException; import org.kaaproject.kaa.server.transport.channel.ChannelContext; import org.kaaproject.kaa.server.transport.message.ErrorBuilder; import org.kaaproject.kaa.server.transport.message.Message; @@ -201,7 +201,7 @@ private ServerSync buildRedirectionResponse(RedirectionRule redirection, ClientS } private void processSessionInitRequest(ActorContext context, SessionInitMessage message) - throws GeneralSecurityException, PlatformEncDecException, InvalidSDKTokenException, EndpointVerificationException { + throws GeneralSecurityException, PlatformEncDecException, InvalidSdkTokenException, EndpointVerificationException { ClientSync request = decodeRequest(message); EndpointObjectHash key = getEndpointObjectHash(request); String sdkToken = getSdkToken(request); @@ -215,7 +215,7 @@ private void processSessionInitRequest(ActorContext context, SessionInitMessage forwardToOpsActor(context, session, request, message); } else { LOG.info("Invalid sdk token received: {}", sdkToken); - throw new InvalidSDKTokenException(); + throw new InvalidSdkTokenException(); } } @@ -276,13 +276,13 @@ private void verifyEndpoint(EndpointObjectHash key, String appToken) throws Endp } private void processSessionRequest(ActorContext context, SessionAwareMessage message) - throws GeneralSecurityException, PlatformEncDecException, InvalidSDKTokenException { + throws GeneralSecurityException, PlatformEncDecException, InvalidSdkTokenException { ClientSync request = decodeRequest(message); if (isSDKTokenValid(message.getSessionInfo().getSdkToken())) { forwardToOpsActor(context, message.getSessionInfo(), request, message); } else { LOG.info("Invalid sdk token received: {}", message.getSessionInfo().getSdkToken()); - throw new InvalidSDKTokenException(); + throw new InvalidSdkTokenException(); } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/event/EndpointEvent.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/event/EndpointEvent.java index d6b24f1dbe..0f3ab12cb7 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/event/EndpointEvent.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/event/EndpointEvent.java @@ -59,7 +59,7 @@ public Event getEvent() { } public String getEventClassFQN() { - return event.getEventClassFQN(); + return event.getEventClassFqn(); } public String getTarget() { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/user/DefaultEndpointUserService.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/user/DefaultEndpointUserService.java index 44f808a048..f54765a678 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/user/DefaultEndpointUserService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/user/DefaultEndpointUserService.java @@ -175,7 +175,7 @@ public EventListenersResponse findListeners(EndpointProfileDto profile, String a String tenantId = cacheService.getTenantIdByAppToken(appToken); Set eventClassIntersectionSet = null; - for (String eventClassFqn : request.getEventClassFQNs()) { + for (String eventClassFqn : request.getEventClassFqns()) { Set eventClassSet = new HashSet<>(); LOG.debug("Lookup event class family id using tenant [{}] and event class fqn {}", tenantId, eventClassFqn); String ecfId = cacheService.getEventClassFamilyIdByEventClassFqn(new EventClassFqnKey(tenantId, eventClassFqn)); diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/DefaultAkkaServiceTest.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/DefaultAkkaServiceTest.java index d1155a5448..74ac08a9be 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/DefaultAkkaServiceTest.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/DefaultAkkaServiceTest.java @@ -123,7 +123,7 @@ import org.kaaproject.kaa.server.sync.platform.AvroEncDec; import org.kaaproject.kaa.server.transport.EndpointRevocationException; import org.kaaproject.kaa.server.transport.EndpointVerificationException; -import org.kaaproject.kaa.server.transport.InvalidSDKTokenException; +import org.kaaproject.kaa.server.transport.InvalidSdkTokenException; import org.kaaproject.kaa.server.transport.channel.ChannelContext; import org.kaaproject.kaa.server.transport.channel.ChannelType; import org.kaaproject.kaa.server.transport.message.ErrorBuilder; @@ -510,7 +510,7 @@ public void testInvalidSDKTokenException() throws Exception { Assert.assertNotNull(akkaService.getActorSystem()); akkaService.process(message); - Mockito.verify(errorBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(Mockito.isA(InvalidSDKTokenException.class)); + Mockito.verify(errorBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(Mockito.isA(InvalidSdkTokenException.class)); } @Test diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/messages/io/NettySessionResponseMessageTest.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/messages/io/NettySessionResponseMessageTest.java index 3c7a45df3f..75fffb97d2 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/messages/io/NettySessionResponseMessageTest.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/messages/io/NettySessionResponseMessageTest.java @@ -35,7 +35,7 @@ public void testNettySessionResponseMessage() { ChannelContext channelContext = new NettyChannelContext(null); ErrorBuilder errorBuilder = new ErrorBuilder() { @Override - public Object[] build(Exception e) { + public Object[] build(Exception exception) { return new Object[0]; } }; diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/user/DefaultEndpointUserServiceTest.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/user/DefaultEndpointUserServiceTest.java index 96085bc6f8..f5e79d0c46 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/user/DefaultEndpointUserServiceTest.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/user/DefaultEndpointUserServiceTest.java @@ -276,7 +276,7 @@ public void detachEndpointDBExceptionFailureTest() { @Test public void getEventListenersTest() { EventListenersRequest request = new EventListenersRequest(); - request.setEventClassFQNs(Arrays.asList("fqn2", "fqn3")); + request.setEventClassFqns(Arrays.asList("fqn2", "fqn3")); request.setRequestId(REQUEST_ID); EndpointProfileDto profileMock = mock(EndpointProfileDto.class); @@ -347,7 +347,7 @@ public void getEventListenersTest() { @Test public void getEventListenersFailure1Test() { EventListenersRequest request = new EventListenersRequest(); - request.setEventClassFQNs(Arrays.asList("fqn2", "fqn3")); + request.setEventClassFqns(Arrays.asList("fqn2", "fqn3")); request.setRequestId(REQUEST_ID); EndpointProfileDto profileMock = mock(EndpointProfileDto.class); @@ -366,7 +366,7 @@ public void getEventListenersFailure1Test() { @Test public void getEventListenersEmptyTest() { EventListenersRequest request = new EventListenersRequest(); - request.setEventClassFQNs(Arrays.asList("fqn2", "fqn3")); + request.setEventClassFqns(Arrays.asList("fqn2", "fqn3")); request.setRequestId(REQUEST_ID); EndpointProfileDto profileMock = mock(EndpointProfileDto.class); diff --git a/server/transports/http/config/src/main/java/org/kaaproject/kaa/server/transport/http/config/HttpTransportConfig.java b/server/transports/http/config/src/main/java/org/kaaproject/kaa/server/transport/http/config/HttpTransportConfig.java index 9dc49ea300..4a9d0d95af 100644 --- a/server/transports/http/config/src/main/java/org/kaaproject/kaa/server/transport/http/config/HttpTransportConfig.java +++ b/server/transports/http/config/src/main/java/org/kaaproject/kaa/server/transport/http/config/HttpTransportConfig.java @@ -17,7 +17,7 @@ package org.kaaproject.kaa.server.transport.http.config; import org.apache.avro.Schema; -import org.kaaproject.kaa.server.common.utils.CRC32Util; +import org.kaaproject.kaa.server.common.utils.Crc32Util; import org.kaaproject.kaa.server.transport.KaaTransportConfig; import org.kaaproject.kaa.server.transport.TransportConfig; import org.kaaproject.kaa.server.transport.http.config.gen.AvroHttpConfig; @@ -31,7 +31,7 @@ public class HttpTransportConfig implements TransportConfig { private static final String HTTP_TRANSPORT_NAME = "org.kaaproject.kaa.server.transport.http"; - private static final int HTTP_TRANSPORT_ID = CRC32Util.crc32(HTTP_TRANSPORT_NAME); + private static final int HTTP_TRANSPORT_ID = Crc32Util.crc32(HTTP_TRANSPORT_NAME); private static final String HTTP_TRANSPORT_CLASS = "org.kaaproject.kaa.server.transports.http.transport.HttpTransport"; private static final String HTTP_TRANSPORT_CONFIG = "http-transport.config"; diff --git a/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/HttpHandler.java b/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/HttpHandler.java index 0b249df094..1df98291da 100644 --- a/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/HttpHandler.java +++ b/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/HttpHandler.java @@ -26,7 +26,7 @@ import org.kaaproject.kaa.server.common.server.NettyChannelContext; import org.kaaproject.kaa.server.transport.EndpointRevocationException; import org.kaaproject.kaa.server.transport.EndpointVerificationException; -import org.kaaproject.kaa.server.transport.InvalidSDKTokenException; +import org.kaaproject.kaa.server.transport.InvalidSdkTokenException; import org.kaaproject.kaa.server.transport.message.ErrorBuilder; import org.kaaproject.kaa.server.transport.message.MessageBuilder; import org.kaaproject.kaa.server.transport.message.MessageHandler; @@ -86,14 +86,14 @@ protected void channelRead0(final ChannelHandlerContext ctx, final AbstractComma } @Override - public Object[] build(Exception e) { + public Object[] build(Exception exception) { HttpResponseStatus status; - if (e instanceof EndpointVerificationException) { + if (exception instanceof EndpointVerificationException) { status = HttpResponseStatus.UNAUTHORIZED; - } else if (e instanceof EndpointRevocationException) { + } else if (exception instanceof EndpointRevocationException) { status = HttpResponseStatus.FORBIDDEN; - } else if (e instanceof GeneralSecurityException || e instanceof IOException || e instanceof IllegalArgumentException - || e instanceof InvalidSDKTokenException) { + } else if (exception instanceof GeneralSecurityException || exception instanceof IOException || exception instanceof IllegalArgumentException + || exception instanceof InvalidSdkTokenException) { status = HttpResponseStatus.BAD_REQUEST; } else { status = HttpResponseStatus.INTERNAL_SERVER_ERROR; diff --git a/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/HttpTransport.java b/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/HttpTransport.java index 3baee5001f..4b44efcb77 100644 --- a/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/HttpTransport.java +++ b/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/HttpTransport.java @@ -118,7 +118,7 @@ protected List getSerializedConnectionInfoList() { RangeExpressionParser rangeExpressionParser = new RangeExpressionParser(); List publicPorts = rangeExpressionParser.getNumbersFromRanges(context.getConfiguration().getPublicPorts()); for (int publicPort : publicPorts) { - byte[] interfaceData = toUTF8Bytes(context.getConfiguration().getPublicInterface()); + byte[] interfaceData = toUtf8Bytes(context.getConfiguration().getPublicInterface()); byte[] publicKeyData = context.getServerKey().getEncoded(); ByteBuffer buf = ByteBuffer.wrap(new byte[SIZE_OF_INT * 3 + interfaceData.length + publicKeyData.length]); buf.putInt(publicKeyData.length); diff --git a/server/transports/tcp/config/src/main/java/org/kaaproject/kaa/server/transport/tcp/config/TcpTransportConfig.java b/server/transports/tcp/config/src/main/java/org/kaaproject/kaa/server/transport/tcp/config/TcpTransportConfig.java index db3c7883a3..826559ccaf 100644 --- a/server/transports/tcp/config/src/main/java/org/kaaproject/kaa/server/transport/tcp/config/TcpTransportConfig.java +++ b/server/transports/tcp/config/src/main/java/org/kaaproject/kaa/server/transport/tcp/config/TcpTransportConfig.java @@ -17,7 +17,7 @@ package org.kaaproject.kaa.server.transport.tcp.config; import org.apache.avro.Schema; -import org.kaaproject.kaa.server.common.utils.CRC32Util; +import org.kaaproject.kaa.server.common.utils.Crc32Util; import org.kaaproject.kaa.server.transport.KaaTransportConfig; import org.kaaproject.kaa.server.transport.TransportConfig; import org.kaaproject.kaa.server.transport.tcp.config.gen.AvroTcpConfig; @@ -30,7 +30,7 @@ @KaaTransportConfig public class TcpTransportConfig implements TransportConfig { private static final String TCP_TRANSPORT_NAME = "org.kaaproject.kaa.server.transport.tcp"; - private static final int TCP_TRANSPORT_ID = CRC32Util.crc32(TCP_TRANSPORT_NAME); + private static final int TCP_TRANSPORT_ID = Crc32Util.crc32(TCP_TRANSPORT_NAME); private static final String TCP_TRANSPORT_CLASS = "org.kaaproject.kaa.server.transports.tcp.transport.TcpTransport"; private static final String TCP_TRANSPORT_CONFIG = "tcp-transport.config"; diff --git a/server/transports/tcp/transport/src/main/java/org/kaaproject/kaa/server/transports/tcp/transport/TcpHandler.java b/server/transports/tcp/transport/src/main/java/org/kaaproject/kaa/server/transports/tcp/transport/TcpHandler.java index 62d9089cff..b68c4e39f1 100644 --- a/server/transports/tcp/transport/src/main/java/org/kaaproject/kaa/server/transports/tcp/transport/TcpHandler.java +++ b/server/transports/tcp/transport/src/main/java/org/kaaproject/kaa/server/transports/tcp/transport/TcpHandler.java @@ -34,7 +34,7 @@ import org.kaaproject.kaa.common.channels.protocols.kaatcp.messages.SyncRequest; import org.kaaproject.kaa.server.common.server.NettyChannelContext; import org.kaaproject.kaa.server.transport.EndpointVerificationException; -import org.kaaproject.kaa.server.transport.InvalidSDKTokenException; +import org.kaaproject.kaa.server.transport.InvalidSdkTokenException; import org.kaaproject.kaa.server.transport.channel.ChannelType; import org.kaaproject.kaa.server.transport.message.ErrorBuilder; import org.kaaproject.kaa.server.transport.message.MessageBuilder; @@ -63,12 +63,12 @@ public class TcpHandler extends SimpleChannelInboundHandler getSerializedConnectionInfoList() { RangeExpressionParser rangeExpressionParser = new RangeExpressionParser(); List publicPorts = rangeExpressionParser.getNumbersFromRanges(context.getConfiguration().getPublicPorts()); for (int publicPort : publicPorts) { - byte[] interfaceData = toUTF8Bytes(context.getConfiguration().getPublicInterface()); + byte[] interfaceData = toUtf8Bytes(context.getConfiguration().getPublicInterface()); byte[] publicKeyData = context.getServerKey().getEncoded(); ByteBuffer buf = ByteBuffer.wrap(new byte[SIZE_OF_INT * 3 + interfaceData.length + publicKeyData.length]); buf.putInt(publicKeyData.length);