aboutsummaryrefslogtreecommitdiffstats
path: root/musictrigger/src/MusicTrigger.java
diff options
context:
space:
mode:
Diffstat (limited to 'musictrigger/src/MusicTrigger.java')
-rwxr-xr-xmusictrigger/src/MusicTrigger.java93
1 files changed, 41 insertions, 52 deletions
diff --git a/musictrigger/src/MusicTrigger.java b/musictrigger/src/MusicTrigger.java
index b5894da1..eb79cb8c 100755
--- a/musictrigger/src/MusicTrigger.java
+++ b/musictrigger/src/MusicTrigger.java
@@ -51,15 +51,23 @@ import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
+
public class MusicTrigger implements ITrigger {
private static final Logger logger = LoggerFactory.getLogger(MusicTrigger.class);
-
public Collection<Mutation> augment(Partition partition)
{
+ new Thread(new Runnable() {
+ public void run() {
+ makeAsyncCall(partition);
+ }
+ }).start();
+ return Collections.emptyList();
+ }
+
+ private void makeAsyncCall(Partition partition) {
boolean isDelete = false;
- logger.info("Step 1: "+partition.partitionLevelDeletion().isLive());
if(partition.partitionLevelDeletion().isLive()) {
} else {
@@ -69,6 +77,7 @@ public class MusicTrigger implements ITrigger {
logger.info("MusicTrigger isDelete: " + isDelete);
String ksName = partition.metadata().ksName;
String tableName = partition.metadata().cfName;
+ String pkValue = partition.metadata().getKeyValidator().getString(partition.partitionKey().getKey());
logger.info("MusicTrigger Table: " + tableName);
boolean isInsert = checkQueryType(partition);
org.json.simple.JSONObject obj = new org.json.simple.JSONObject();
@@ -121,7 +130,7 @@ public class MusicTrigger implements ITrigger {
}
}
} catch (Exception e) {
-
+ logger.info("Exception while constructing.. "+e.getMessage());
}
obj.put("updateList", updateList);
} else {
@@ -132,11 +141,12 @@ public class MusicTrigger implements ITrigger {
logger.info("Sending response: "+obj.toString());
try {
notifyMusic(obj.toString());
+ logger.info("MUSIC was notified.. "+obj.toString());
} catch(Exception e) {
- e.printStackTrace();
logger.error("Notification failed..."+e.getMessage());
+ logger.info("Notification failed..."+e.getMessage());
}
- return Collections.emptyList();
+
}
private int fromByteArray(byte[] bytes) {
@@ -160,62 +170,41 @@ public class MusicTrigger implements ITrigger {
}
private void notifyMusic(String request) {
- System.out.println("notifyMusic...");
+ logger.info("notifyMusic...");
Client client = Client.create();
WebResource webResource = client.resource("http://localhost:8080/MUSIC/rest/v2/admin/callbackOps");
JSONObject data = new JSONObject();
data.setData(request);
-
- ClientResponse response = webResource.accept("application/json").type("application/json")
+ ClientResponse response = null;
+ try {
+ response = webResource.accept("application/json").type("application/json")
.post(ClientResponse.class, data);
+ } catch (Exception e) {
+ logger.info("Exception while notifying MUSIC. Retrying..");
+ try {
+ response = webResource.accept("application/json").type("application/json")
+ .post(ClientResponse.class, data);
+ } catch (Exception e1) {
+ logger.info("Exception while notifying MUSIC. Stopping retry attempts..");
+ }
+ }
if(response.getStatus() != 200){
- System.out.println("Exception while notifying MUSIC...");
+ logger.info("Exception while notifying MUSIC...");
+ try {
+ response = webResource.accept("application/json").type("application/json")
+ .post(ClientResponse.class, data);
+ } catch (Exception e) {
+ logger.info("Exception while notifying MUSIC. Retrying..");
+ try {
+ response = webResource.accept("application/json").type("application/json")
+ .post(ClientResponse.class, data);
+ } catch (Exception e1) {
+ logger.info("Exception while notifying MUSIC. Stopping retry attempts..");
+ }
+ }
}
- /*response.getHeaders().put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.APPLICATION_JSON));
- response.bufferEntity();
- String x = response.getEntity(String.class);
- System.out.println("Response: "+x);*/
-
}
- /*public Collection<Mutation> augment(Partition partition) {
-
- String tableName = partition.metadata().cfName;
- System.out.println("Table: " + tableName);
-
- JSONObject obj = new JSONObject();
- obj.put("message_id", partition.metadata().getKeyValidator().getString(partition.partitionKey().getKey()));
-
-
- try {
- UnfilteredRowIterator it = partition.unfilteredIterator();
- while (it.hasNext()) {
- Unfiltered un = it.next();
- Clustering clt = (Clustering) un.clustering();
- Iterator<Cell> cls = partition.getRow(clt).cells().iterator();
- Iterator<ColumnDefinition> columns = partition.getRow(clt).columns().iterator();
-
- while(cls.hasNext()){
- Cell cell = cls.next();
- String data = new String(cell.value().array()); // If cell type is text
- System.out.println(cell + " : " +data);
-
- }
- while(columns.hasNext()){
- ColumnDefinition columnDef = columns.next();
- Cell cell = cls.next();
- String data = new String(cell.value().array()); // If cell type is text
- obj.put(columnDef.toString(), data);
- }
- }
- } catch (Exception e) {
- }
-
- System.out.println(obj.toString());
-
- return Collections.emptyList();
- }*/
-
} \ No newline at end of file