Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill380 committed Sep 30, 2016
1 parent 210430b commit 77bd66c
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 74 deletions.
Expand Up @@ -25,11 +25,11 @@
/**
* A service to manage security credentials.
*
* In general, each application has its own independent credentials service used
* <p>In general, each application has its own independent credentials service used
* as a bridge to some external system. Since Kaa acts as such a system by
* default, a single credentials service is enough to be used across all
* applications. Its methods require an additonal parameter, though, namely the
* application ID.
* application ID.</p>
*
* @author Andrew Shvayka
* @author Bohdan Khablenko
Expand All @@ -45,7 +45,8 @@ public interface CredentialsService {
* @return The credentials provided
* @throws CredentialsServiceException - if an unexpected exception occures.
*/
CredentialsDto provideCredentials(String applicationId, CredentialsDto credentials) throws CredentialsServiceException;
CredentialsDto provideCredentials(String applicationId, CredentialsDto credentials)
throws CredentialsServiceException;

/**
* Returns the credentials by ID.
Expand All @@ -55,25 +56,29 @@ public interface CredentialsService {
* @return The credentials with the given ID
* @throws CredentialsServiceException - if an unexpected exception occures.
*/
Optional<CredentialsDto> lookupCredentials(String applicationId, String credentialsId) throws CredentialsServiceException;
Optional<CredentialsDto> lookupCredentials(String applicationId, String credentialsId)
throws CredentialsServiceException;

/**
* Sets the status of the given credentials to
* {@link CredentialsStatus#IN_USE}.
*
* @param applicationId The application ID
* @param credentialsId The credentials ID
* @throws CredentialsServiceException - if the credentials are not {@link CredentialsStatus#AVAILABLE}.
* @throws CredentialsServiceException - if the credentials are not
* {@link CredentialsStatus#AVAILABLE}.
*/
void markCredentialsInUse(String applicationId, String credentialsId) throws CredentialsServiceException;
void markCredentialsInUse(String applicationId, String credentialsId)
throws CredentialsServiceException;

/**
* Revokes the given credentials by setting their status to
* {@link CredentialsStatus#REVOKED}.
*
* @param applicationId The application ID
* @param credentialsId The credentials ID
* @throws CredentialsServiceException - if an unexpected exception occures.
* @throws CredentialsServiceException - if an unexpected exception occurs.
*/
void markCredentialsRevoked(String applicationId, String credentialsId) throws CredentialsServiceException;
void markCredentialsRevoked(String applicationId, String credentialsId)
throws CredentialsServiceException;
}
Expand Up @@ -126,7 +126,8 @@ public interface EndpointService {
* @param endpointConfigurationDto the endpoint configuration dto
* @return the endpoint configuration dto
*/
EndpointConfigurationDto saveEndpointConfiguration(EndpointConfigurationDto endpointConfigurationDto);
EndpointConfigurationDto saveEndpointConfiguration(
EndpointConfigurationDto endpointConfigurationDto);

/**
* Find endpoint profile by key hash.
Expand All @@ -153,7 +154,7 @@ public interface EndpointService {
TopicListEntryDto findTopicListEntryByHash(byte[] hash);

/**
* Save topic list entry
* Save topic list entry.
*
* @param topicListEntryDto the endpoint list entry dto
* @return the topic list entry dto
Expand Down Expand Up @@ -190,7 +191,8 @@ public interface EndpointService {
* @param profile the profile
* @return the endpoint profile dto
*/
EndpointProfileDto attachEndpointToUser(String userExternalId, String tenantId, EndpointProfileDto profile);
EndpointProfileDto attachEndpointToUser(String userExternalId, String tenantId,
EndpointProfileDto profile);

/**
* Attach endpoint profile to user.
Expand All @@ -200,15 +202,21 @@ public interface EndpointService {
* @return the endpoint profile dto
*/

@Retryable(maxAttempts = 10, backoff = @Backoff(delay = 100), value = {KaaOptimisticLockingFailureException.class})
EndpointProfileDto attachEndpointToUser(String endpointUserId, String endpointAccessToken) throws KaaOptimisticLockingFailureException;
@Retryable(maxAttempts = 10,
backoff = @Backoff(delay = 100),
value = {KaaOptimisticLockingFailureException.class}
)
EndpointProfileDto attachEndpointToUser(String endpointUserId, String endpointAccessToken)
throws KaaOptimisticLockingFailureException;

/**
* Detach endpoint profile from user.
*
* @param detachEndpoint the detach endpoint
*/
@Retryable(maxAttempts = 10, backoff = @Backoff(delay = 100), value = {KaaOptimisticLockingFailureException.class})
@Retryable(maxAttempts = 10,
backoff = @Backoff(delay = 100),
value = {KaaOptimisticLockingFailureException.class})
void detachEndpointFromUser(EndpointProfileDto detachEndpoint);

/**
Expand Down Expand Up @@ -259,7 +267,8 @@ public interface EndpointService {
* @param tenantId the tenant id
* @return the list of endpoint profiles
*/
List<EndpointProfileDto> findEndpointProfilesByExternalIdAndTenantId(String externalId, String tenantId);
List<EndpointProfileDto> findEndpointProfilesByExternalIdAndTenantId(String externalId,
String tenantId);

/**
* Returns the default group for the given application.
Expand Down
Expand Up @@ -16,7 +16,8 @@

/**
* Provides classes and interfaces used to decode platform level data to {@link
* org.kaaproject.kaa.server.sync.ClientSync} and encode {@link org.kaaproject.kaa.server.sync.ServerSync}
* org.kaaproject.kaa.server.sync.ClientSync} and encode
* {@link org.kaaproject.kaa.server.sync.ServerSync}
*/
package org.kaaproject.kaa.server.sync.platform;

Expand Up @@ -58,7 +58,6 @@
*/
public final class NeighborConnection<T extends NeighborTemplate<V>, V> {


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

/**
Expand Down Expand Up @@ -120,7 +119,7 @@ public NeighborConnection(ConnectionInfo connectionInfo, int maxNumberConnection
this.maxNumberConnection = maxNumberConnection;
this.socketTimeout = socketTimeout;
this.template = template;
this.id = Neighbors.getServerID(connectionInfo);
this.id = Neighbors.getServerId(connectionInfo);
}

public NeighborConnection(ConnectionInfo connectionInfo,
Expand Down
Expand Up @@ -25,6 +25,6 @@ public interface NeighborTemplate<V> {

void process(OperationsThriftService.Iface client, List<V> messages) throws TException;

void onServerError(String serverId, Exception e);
void onServerError(String serverId, Exception ex);

}
Expand Up @@ -41,9 +41,6 @@
*/
public class Neighbors<T extends NeighborTemplate<V>, V> {

/**
* The Constant LOG.
*/
private static final Logger LOG = LoggerFactory.getLogger(Neighbors.class);

private final KaaThriftService serviceType;
Expand Down Expand Up @@ -73,8 +70,8 @@ public Neighbors(KaaThriftService serviceType, T template, int maxNumberNeighbor
* @param info ConnectionInfo
* @return server ID in format thriftHost:thriftPort
*/
public static String getServerID(ConnectionInfo info) {
return getServerID(KaaThriftService.OPERATIONS_SERVICE, info);
public static String getServerId(ConnectionInfo info) {
return getServerId(KaaThriftService.OPERATIONS_SERVICE, info);
}

/**
Expand All @@ -84,7 +81,7 @@ public static String getServerID(ConnectionInfo info) {
* @param info ConnectionInfo
* @return server ID in format thriftHost:thriftPort
*/
public static String getServerID(KaaThriftService service, ConnectionInfo info) {
public static String getServerId(KaaThriftService service, ConnectionInfo info) {
StringBuffer sb = new StringBuffer();
sb.append(info.getThriftHost());
sb.append(":");
Expand All @@ -99,16 +96,16 @@ public void sendMessage(ConnectionInfo info, V msg) {
}

public void sendMessages(ConnectionInfo info, Collection<V> msg) {
NeighborConnection<T, V> neighbor = neigbors.get(getServerID(info));
NeighborConnection<T, V> neighbor = neigbors.get(getServerId(info));
if (neighbor != null) {
try {
neighbor.sendMessages(msg);
} catch (InterruptedException e) {
} catch (InterruptedException ex) {
LOG.error("Failed to send message to {}", neighbor.getId());
throw new RuntimeException(e);
throw new RuntimeException(ex);
}
} else {
LOG.warn("Can't find server for id {}", getServerID(info));
LOG.warn("Can't find server for id {}", getServerId(info));
}
}

Expand All @@ -124,7 +121,7 @@ public void brodcastMessages(Collection<V> msgs) {
LOG.trace("Broadcasting to {} neighbor", neighbor);
try {
neighbor.sendMessages(msgs);
} catch (InterruptedException e) {
} catch (InterruptedException ex) {
LOG.warn("Failed to send message to {}", neighbor.getId());
}
}
Expand All @@ -144,14 +141,13 @@ public void shutdown() {
/**
* Return current list of Neighbors.
*
* @return List<NeighborConnection> neighbors.
*/
public List<NeighborConnection<T, V>> getNeighbors() {
return new LinkedList<NeighborConnection<T, V>>(neigbors.values());
}

/**
* Return specific Neighbor connection by Id
* Return specific Neighbor connection by Id.
*
* @param serverId String in format thriftHost:thriftPort
* @return NeighborConnection or null if such server not exist
Expand All @@ -160,8 +156,9 @@ public NeighborConnection<T, V> getNeghborConnection(String serverId) {
return neigbors.get(serverId);
}

public void setZkNode(KaaThriftService service, ConnectionInfo connectionInfo, WorkerNodeTracker zkNode) {
setZkNode(getServerID(service, connectionInfo), zkNode);
public void setZkNode(KaaThriftService service, ConnectionInfo connectionInfo,
WorkerNodeTracker zkNode) {
setZkNode(getServerId(service, connectionInfo), zkNode);
}

/**
Expand All @@ -185,13 +182,14 @@ public void onNodeAdded(OperationsNodeInfo nodeInfo) {

@Override
public void onNodeRemoved(OperationsNodeInfo nodeInfo) {
String opId = getServerID(nodeInfo.getConnectionInfo());
String opId = getServerId(nodeInfo.getConnectionInfo());
if (!zkId.equals(opId)) {
NeighborConnection<T, V> connection = neigbors.remove(opId);
if (connection != null) {
connection.shutdown();
}
LOG.info("Operations server {} removed to {} Neighbors list ({}). Now {} neighbors", opId, neigbors.size());
LOG.info("Operations server {} removed to {} Neighbors list ({}). Now {} neighbors",
opId, neigbors.size());
}
}
});
Expand All @@ -205,12 +203,15 @@ public void onNodeRemoved(OperationsNodeInfo nodeInfo) {

private void addOpsServer(OperationsNodeInfo opServer) {
LOG.trace("[{}] Building id for {}", zkId, opServer.getConnectionInfo());
String opId = getServerID(serviceType, opServer.getConnectionInfo());
String opId = getServerId(serviceType, opServer.getConnectionInfo());
if (!zkId.equals(opId)) {
LOG.trace("Adding {} to {}", opId, neigbors);
neigbors.putIfAbsent(opId, new NeighborConnection<T, V>(opServer.getConnectionInfo(), maxNumberNeighborConnections, template));
neigbors.putIfAbsent(opId, new NeighborConnection<T, V>(opServer.getConnectionInfo(),
maxNumberNeighborConnections, template));

neigbors.get(opId).start();
LOG.info("Operations server {} added/updated to {} Neighbors list. Now {} neighbors", opId, zkId, neigbors.size());
LOG.info("Operations server {} added/updated to {} Neighbors list. Now {} neighbors",
opId, zkId, neigbors.size());
}
}
}
Expand Up @@ -932,7 +932,7 @@ public void editUserConfiguration(EndpointUserConfigurationDto configuration)
configuration.getUserId(), configuration.getAppToken(),
configuration.getSchemaVersion(), hash.getDataBuf());
if (LOG.isTraceEnabled()) {
LOG.trace("Sending message {} to [{}]", msg, Neighbors.getServerID(
LOG.trace("Sending message {} to [{}]", msg, Neighbors.getServerId(
server.getConnectionInfo()));
}
neighbors.sendMessage(server.getConnectionInfo(), OperationsServiceMsg.fromUpdate(msg));
Expand Down Expand Up @@ -1583,7 +1583,7 @@ public EndpointNotificationDto editUnicastNotification(EndpointNotificationDto n
nf.setNotificationId(notificationDto.getId());
if (LOG.isTraceEnabled()) {
LOG.trace("Sending message {} to [{}]",
nf, Neighbors.getServerID(server.getConnectionInfo()));
nf, Neighbors.getServerId(server.getConnectionInfo()));
}
neighbors.sendMessage(server.getConnectionInfo(), OperationsServiceMsg.fromNotification(nf));
} else {
Expand Down Expand Up @@ -1618,7 +1618,7 @@ public EndpointProfileDto updateServerProfile(String endpointKeyHash, int versio
nf.setActorClassifier(ThriftActorClassifier.GLOBAL);
if (LOG.isTraceEnabled()) {
LOG.trace("Sending message {} to [{}]",
nf, Neighbors.getServerID(server.getConnectionInfo()));
nf, Neighbors.getServerId(server.getConnectionInfo()));
}
neighbors.sendMessage(server.getConnectionInfo(),
OperationsServiceMsg.fromServerProfileUpdateMessage(nf));
Expand Down
Expand Up @@ -24,8 +24,8 @@ public ControlServiceException(String message) {
super(message);
}

public ControlServiceException(Exception e) {
super(e);
public ControlServiceException(Exception ex) {
super(ex);
}

}
Expand Up @@ -31,14 +31,10 @@
import java.io.InputStreamReader;
import java.util.List;

/**
* The Class SdkGenerator.
*/

public abstract class SdkGenerator {

/**
* The Constant LOG.
*/

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

/**
Expand All @@ -62,10 +58,10 @@ static String readFile(File file) throws IOException {
}
reader.close();
result = fileData.toString();
} catch (IOException e) {
} catch (IOException ex) {
LOG.error("Unable to read from specified file '"
+ file + "'! Error: " + e.getMessage(), e);
throw e;
+ file + "'! Error: " + ex.getMessage(), ex);
throw ex;
}
return result;
}
Expand All @@ -78,10 +74,11 @@ static String readFile(File file) throws IOException {
* @throws IOException Signals that an I/O exception has occurred.
*/
public static String readResource(String resource) throws IOException {
String result = null;
String result;
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;
Expand All @@ -91,10 +88,10 @@ public static String readResource(String resource) throws IOException {
}
reader.close();
result = fileData.toString();
} catch (IOException e) {
} catch (IOException ex) {
LOG.error("Unable to read from specified resource '"
+ resource + "'! Error: " + e.getMessage(), e);
throw e;
+ resource + "'! Error: " + ex.getMessage(), ex);
throw ex;
}
return result;
}
Expand Down

0 comments on commit 77bd66c

Please sign in to comment.