Skip to content

Commit

Permalink
Merge pull request #5 from AO-StreetArt/dev
Browse files Browse the repository at this point in the history
Project Cleanup
  • Loading branch information
AO-StreetArt committed Oct 8, 2017
2 parents b1f1adc + 60ff52c commit b628cfe
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 72 deletions.
4 changes: 2 additions & 2 deletions docs/pages/quickstart.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. _quickstart:

Getting Started with CLyman
===========================
Getting Started with Adrestia
=============================

:ref:`Go Home <index>`

Expand Down
62 changes: 31 additions & 31 deletions src/main/java/adrestia/DvsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public DvsManager() {
}

// Check if a service is active
private static boolean is_socket_active(int serviceType) {
private static boolean isSocketActive(int serviceType) {
if (serviceType == ivanType) {
if (crazyIvanSocket != null) {
return true;
Expand All @@ -178,7 +178,7 @@ private static boolean is_socket_active(int serviceType) {
}

// Get the active socket for a service
private static ZMQ.Socket get_socket(int serviceType) {
private static ZMQ.Socket getSocket(int serviceType) {
if (serviceType == ivanType) {
return crazyIvanSocket;
} else if (serviceType == clymanType) {
Expand All @@ -188,7 +188,7 @@ private static ZMQ.Socket get_socket(int serviceType) {
}

// Destroy the active socket for a service
private void destroy_socket(int serviceType) {
private void destroySocket(int serviceType) {
if (serviceType == ivanType) {
if (crazyIvanSocket != null) {
poller.unregister(crazyIvanSocket);
Expand All @@ -205,9 +205,9 @@ private void destroy_socket(int serviceType) {
}

// Reset the active socket for a service
private void reset_socket(int serviceType) {
private void resetSocket(int serviceType) {
// First, destroy the socket
destroy_socket(serviceType);
destroySocket(serviceType);
// Then, create a new socket
if (serviceType == ivanType) {
crazyIvanSocket = context.createSocket(ZMQ.REQ);
Expand All @@ -223,13 +223,13 @@ private void reset_socket(int serviceType) {
*/
@PreDestroy
public void destroy() {
destroy_socket(ivanType);
destroy_socket(clymanType);
destroySocket(ivanType);
destroySocket(clymanType);
context.destroy();
}

// Connect to the current socket for a service
private void connect_to_socket(int serviceType) {
private void connectToSocket(int serviceType) {
// Pull the URL String
String uriString = null;
if (serviceType == ivanType) {
Expand All @@ -245,11 +245,11 @@ private void connect_to_socket(int serviceType) {
String zmqAddr = String.format("tcp://%s:%s", hostName, portStr);
logger.info("Connecting to server: " + zmqAddr);
// Connect to the service
get_socket(serviceType).connect(zmqAddr);
getSocket(serviceType).connect(zmqAddr);
}

// Report a failure of a service
private void report_failure(int serviceType) {
private void reportFailure(int serviceType) {
// Is the current host already on the greylist?
Object cacheResp = null;
if (serviceType == clymanType) {
Expand All @@ -262,7 +262,7 @@ private void report_failure(int serviceType) {
// Grab the mutex so we ensure we operate atomically on connections
try {
// Eliminate the socket
destroy_socket(serviceType);
destroySocket(serviceType);
if (cacheResp != null) {
// We have found an entry in the greylist, add the host to the blacklist
if (serviceType == clymanType) {
Expand All @@ -285,7 +285,7 @@ private void report_failure(int serviceType) {
}

// Setup method to find and connect to an instance of Crazy Ivan
private void find_service(int serviceType) {
private void findService(int serviceType) {
logger.info("Finding a new Crazy Ivan instance");
// Find an instance of CrazyIvan
List<ServiceInstance> serviceInstances = null;
Expand Down Expand Up @@ -322,16 +322,16 @@ private void find_service(int serviceType) {
try {
// Crazy Ivan ZMQ Context & Socket
// Close any existing socket before creating a new one
reset_socket(serviceType);
resetSocket(serviceType);

// Connect to the new socket
// First we need to format the address from Consul. We also assume
// tcp Communications between this class and Crazy Ivan
connect_to_socket(serviceType);
connectToSocket(serviceType);
} catch (Exception e) {
logger.error("Error connecting to Crazy Ivan instance");
logger.error(e.getMessage());
report_failure(serviceType);
reportFailure(serviceType);
}
// Exit the loop
break;
Expand All @@ -349,20 +349,20 @@ private void find_service(int serviceType) {
}
}

private String send_msg_recursive(
private String sendMsgRecursive(
String msg, int timeout, int retries, int serviceType) {
logger.info("Attempting to send message to Crazy Ivan");
// Find a Crazy Ivan instance, if necessary
if (!is_socket_active(serviceType)) {
find_service(serviceType);
if (!isSocketActive(serviceType)) {
findService(serviceType);
}
// Response Processing
int retriesLeft = retries;
while (retriesLeft > 0
&& !Thread.currentThread().isInterrupted()
&& is_socket_active(serviceType)) {
&& isSocketActive(serviceType)) {
// We send a request, then we work to get a reply
get_socket(serviceType).send(msg.getBytes(ZMQ.CHARSET), 0);
getSocket(serviceType).send(msg.getBytes(ZMQ.CHARSET), 0);

// We are going to use a poller with a timeout to get the value
// Pattern from ZMQ Guide - Lazy Pirate Client
Expand All @@ -377,22 +377,22 @@ && is_socket_active(serviceType)) {
// reply is valid. If we didn't get a reply we close the client
// socket and resend the request. We try a number of times
// before finally abandoning:
if (poller.isReadable(get_socket(serviceType))) {
if (poller.isReadable(getSocket(serviceType))) {
// We got a reply from the server
return get_socket(serviceType).recvStr();
return getSocket(serviceType).recvStr();
} else if (--retriesLeft == 0) {
logger.error("Reporting Crazy Ivan Failure");
report_failure(serviceType);
reportFailure(serviceType);
// Keep trying to send the message until we succeed or run out of
// Crazy Ivan instances
return send_msg_recursive(msg, timeout, retries, serviceType);
return sendMsgRecursive(msg, timeout, retries, serviceType);
} else {
logger.warn("No response from server, retrying");
// Old socket is confused; close it and open a new one
reset_socket(serviceType);
connect_to_socket(serviceType);
resetSocket(serviceType);
connectToSocket(serviceType);
// Send request again, on new socket
get_socket(serviceType).send(msg.getBytes(ZMQ.CHARSET), 0);
getSocket(serviceType).send(msg.getBytes(ZMQ.CHARSET), 0);
}
if (rc < 0) {
break;
Expand All @@ -405,7 +405,7 @@ && is_socket_active(serviceType)) {
/**
* Send a message to Crazy Ivan, return the response.
*/
public String send_to_ivan(String msg, int timeout, int retries) {
public String sendToIvan(String msg, int timeout, int retries) {
// Grab the mutex so we ensure we operate atomically on connections
try {
crazyIvanMutex.acquire();
Expand All @@ -415,7 +415,7 @@ public String send_to_ivan(String msg, int timeout, int retries) {
}
// Actually try to send the message
try {
return send_msg_recursive(msg, timeout, retries, ivanType);
return sendMsgRecursive(msg, timeout, retries, ivanType);
} catch (Exception e) {
logger.error("Error Sending message to Crazy Ivan: ", e);
} finally {
Expand All @@ -428,7 +428,7 @@ public String send_to_ivan(String msg, int timeout, int retries) {
/**
* Send a message to CLyman, return the response.
*/
public String send_to_clyman(String msg, int timeout, int retries) {
public String sendToClyman(String msg, int timeout, int retries) {
// Grab the mutex so we ensure we operate atomically on connections
try {
clymanMutex.acquire();
Expand All @@ -438,7 +438,7 @@ public String send_to_clyman(String msg, int timeout, int retries) {
}
// Actually try to send the message
try {
return send_msg_recursive(msg, timeout, retries, clymanType);
return sendMsgRecursive(msg, timeout, retries, clymanType);
} catch (Exception e) {
logger.error("Error Sending message to CLyman: ", e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,14 @@
*/
public class Scene {

@JsonProperty("key")
private String key;
@JsonProperty("name")
private String name;
@JsonProperty("region")
private String region;
@JsonProperty("latitude")
private double latitude;
@JsonProperty("longitude")
private double longitude;
@JsonProperty("distance")
private double distance;
@JsonProperty("asset_ids")
private String[] assets;
@JsonProperty("tags")
private String[] tags;
@JsonProperty("devices")
private UserDevice[] deviceList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public class SceneList {
private int msgType;
@JsonProperty("num_records")
private long numRecords;
@JsonProperty("scenes")
private Scene[] sceneList;
private Scene[] scenes;
@JsonProperty("err_code")
private int errorCode;
@JsonProperty("err_msg")
Expand All @@ -51,16 +50,16 @@ public SceneList() {
* Complete SceneList constructor.
* @param msgType Integer Value representing the Type of Message.
* @param numRecords The Number of Records in the Scene List.
* @param sceneList The list of Scenes stored in the Scene List.
* @param scenes The list of Scenes stored in the Scene List.
* @param errCode The Integer Error Code for the message.
* @param errMsg The Human-Readable Error Code in the message.
* @param transactionId The Unique Identifier for a particular transaction
*/
public SceneList(int msgType, long numRecords, Scene[] sceneList,
public SceneList(int msgType, long numRecords, Scene[] scenes,
int errCode, String errMsg, String transactionId) {
this.msgType = msgType;
this.numRecords = numRecords;
this.sceneList = sceneList;
this.scenes = scenes;
this.errorCode = errCode;
this.errorMessage = errMsg;
this.transactionId = transactionId;
Expand Down Expand Up @@ -108,7 +107,7 @@ public void setNumRecords(long newNumRecords) {
*/
@JsonGetter("scenes")
public Scene[] getSceneList() {
return this.sceneList;
return this.scenes;
}

/**
Expand All @@ -117,7 +116,7 @@ public Scene[] getSceneList() {
*/
@JsonSetter("scenes")
public void setSceneList(Scene[] newSceneList) {
this.sceneList = newSceneList;
this.scenes = newSceneList;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
*/
public class Transform {

@JsonProperty("translation")
private double[] translation;

@JsonProperty("rotation")
private double[] rotation;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
*/
public class UserDevice {

@JsonProperty("key")
private String key;
@JsonProperty("transform")
private Transform transform;


Expand Down

0 comments on commit b628cfe

Please sign in to comment.