Skip to content

Commit

Permalink
Fixed some code style warns.
Browse files Browse the repository at this point in the history
  • Loading branch information
Acarus committed Sep 28, 2016
1 parent e9f06cb commit ea2cbf5
Show file tree
Hide file tree
Showing 86 changed files with 939 additions and 587 deletions.
Expand Up @@ -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;
Expand Down
Expand Up @@ -35,4 +35,5 @@
* @see org.kaaproject.kaa.client.Kaa
* @see org.kaaproject.kaa.client.KaaClient
*/

package org.kaaproject.kaa.client;
Expand Up @@ -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);
}
}
}
Expand Down
Expand Up @@ -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;
Expand All @@ -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<SocketChannel> sInit = configureInitializer();
ChannelInitializer<SocketChannel> 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);
}
}

Expand All @@ -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");
Expand All @@ -112,21 +115,23 @@ public void shutdown() {
LOG.info("NettyHttpServer stopping...");
if (bossGroup != null) {
try {
Future<? extends Object> f = bossGroup.shutdownGracefully(250, 1000, TimeUnit.MILLISECONDS);
f.await();
} catch (InterruptedException e) {
LOG.trace("NettyHttpServer stopping: bossGroup error", e);
Future<? extends Object> 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");
}
}
if (workerGroup != null) {
try {
Future<? extends Object> f = workerGroup.shutdownGracefully(250, 1000, TimeUnit.MILLISECONDS);
f.await();
} catch (InterruptedException e) {
LOG.trace("NettyHttpServer stopping: workerGroup error", e);
Future<? extends Object> 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");
Expand Down
Expand Up @@ -43,7 +43,7 @@ public CommandFactory(List<KaaCommandProcessorFactory<U, V>> factories) {

/**
* getCommandProcessor - used to instantiate CommandProcessor for specific
* URI
* URI.
*
* @param uri - HTTP request URI, should have following format: /DOMAIN/CommandName
* @return - CommandProcessor
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -38,13 +38,14 @@

import java.util.List;

public abstract class AbstractVersionableCassandraDao<T extends HasVersion, K> extends AbstractCassandraDao<T, K> {
public abstract class AbstractVersionableCassandraDao<T extends HasVersion, K>
extends AbstractCassandraDao<T, K> {

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 {
Expand All @@ -58,18 +59,23 @@ private Clause[] buildKeyClauses(CassandraEntityMapper<T> 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<T> 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<T> 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);
}
}
Expand All @@ -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) {
Expand All @@ -98,7 +106,8 @@ private T updateLocked(T entity) {

private T insertLocked(T entity) {
Insert insert = insertInto(getColumnFamilyName()).ifNotExists();
CassandraEntityMapper<T> entityMapper = CassandraEntityMapper.getEntityMapperForClass(getColumnFamilyClass(), cassandraClient);
CassandraEntityMapper<T> entityMapper = CassandraEntityMapper.getEntityMapperForClass(
getColumnFamilyClass(), cassandraClient);
for (String name : entityMapper.getKeyColumnNames()) {
insert.value(name, entityMapper.getColumnValueForName(name, entity, cassandraClient));
}
Expand Down
Expand Up @@ -42,7 +42,9 @@
import java.util.Optional;

@Repository
public class CredentialsCassandraDao extends AbstractCassandraDao<CassandraCredentials, ByteBuffer> implements CredentialsDao<CassandraCredentials> {
public class CredentialsCassandraDao
extends AbstractCassandraDao<CassandraCredentials, ByteBuffer>
implements CredentialsDao<CassandraCredentials> {

private static final Logger LOG = LoggerFactory.getLogger(CredentialsCassandraDao.class);

Expand All @@ -64,18 +66,23 @@ public CassandraCredentials save(String applicationId, CredentialsDto credential

@Override
public Optional<CassandraCredentials> 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));
return Optional.ofNullable(this.findOneByStatement(query));
}

@Override
public Optional<CassandraCredentials> updateStatus(String applicationId, String credentialsId, CredentialsStatus status) {
LOG.debug("Updating credentials status with applicationID[{}] and credentialsID[{}] to STATUS[{}]",
public Optional<CassandraCredentials> 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);
Expand All @@ -84,7 +91,8 @@ public Optional<CassandraCredentials> 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));
Expand Down
Expand Up @@ -30,10 +30,12 @@
import java.nio.ByteBuffer;

@Repository(value = "endpointConfigurationDao")
public class EndpointConfigurationCassandraDao extends AbstractCassandraDao<CassandraEndpointConfiguration, ByteBuffer>
public class EndpointConfigurationCassandraDao
extends AbstractCassandraDao<CassandraEndpointConfiguration, ByteBuffer>
implements EndpointConfigurationDao<CassandraEndpointConfiguration> {

private static final Logger LOG = LoggerFactory.getLogger(EndpointConfigurationCassandraDao.class);
private static final Logger LOG =
LoggerFactory.getLogger(EndpointConfigurationCassandraDao.class);

@Override
protected Class<CassandraEndpointConfiguration> getColumnFamilyClass() {
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -135,12 +135,12 @@ private CassandraEndpointProfile saveProfile(CassandraEndpointProfile profile) {
ByteBuffer epKeyHash = profile.getEndpointKeyHash();
List<Statement> 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(
Expand All @@ -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());
Expand All @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit ea2cbf5

Please sign in to comment.