Skip to content

Commit e0f061c

Browse files
committed
DM-8179: Preserve background jobs and statuses beyond a browser session.
- refactor AppDataCntlr.js
1 parent fd2b7e2 commit e0f061c

23 files changed

+547
-363
lines changed

src/firefly/java/edu/caltech/ipac/firefly/core/background/BackgroundStatus.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class BackgroundStatus implements Serializable {
3131
// --------Keys -------------------
3232
public static final String TYPE = "TYPE";
3333
public static final String ID = "ID";
34+
public static final String TITLE = "Title";
3435
public static final String ATTRIBUTE = "ATTRIBUTES";
3536
public static final String STATE = "STATE";
3637
public static final String DATA_SOURCE = "DATA_SOURCE";

src/firefly/java/edu/caltech/ipac/firefly/data/ServerEvent.java

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
*/
1010

1111

12+
import edu.caltech.ipac.firefly.server.ServerContext;
1213
import edu.caltech.ipac.firefly.util.event.Name;
14+
import edu.caltech.ipac.util.StringUtils;
1315
import org.apache.xpath.operations.*;
1416

1517
import java.io.Serializable;
@@ -19,21 +21,16 @@
1921
* @author Trey Roby
2022
*/
2123
public class ServerEvent implements Serializable {
22-
public enum Scope {SELF, CHANNEL, WORLD}
2324
public static final String SERVER_CONN_ID = "-1";
24-
public enum DataType {JSON, BG_STATUS, STRING};
25-
2625
private Name name;
27-
private EventTarget target;
26+
private EventTarget target;;
2827
private DataType dataType = DataType.STRING;
2928
private Serializable data;
3029
private String from;
31-
3230
//======================================================================
3331
//----------------------- Constructors ---------------------------------
3432
//======================================================================
3533
public ServerEvent() {}
36-
3734
public ServerEvent(Name name, Scope scope, Serializable data) {
3835
this(name, new EventTarget(scope), DataType.JSON, data, null);
3936
}
@@ -58,10 +55,6 @@ public ServerEvent(Name name, EventTarget target, DataType dataType, Serializabl
5855
this.from = from;
5956
}
6057

61-
public void setFrom(String from) {
62-
this.from = from;
63-
}
64-
6558
public DataType getDataType() {
6659
return dataType;
6760
}
@@ -82,6 +75,10 @@ public String getFrom() {
8275
return from;
8376
}
8477

78+
public void setFrom(String from) {
79+
this.from = from;
80+
}
81+
8582
public String toJsonString() {
8683
StringBuffer sb = new StringBuffer("{");
8784
sb.append("\"name\":\"").append(name.getName()).append("\", ");
@@ -91,6 +88,10 @@ public String toJsonString() {
9188
return sb.toString();
9289
}
9390

91+
public enum Scope {SELF, CHANNEL, USER, WORLD}
92+
93+
public enum DataType {JSON, BG_STATUS, STRING}
94+
9495
//====================================================================
9596
//
9697
//====================================================================
@@ -100,11 +101,19 @@ public static class EventTarget implements Serializable {
100101
private Scope scope;
101102
private String connID;
102103
private String channel;
104+
private String userKey;
103105

104106
public EventTarget() {}
105107

106108
public EventTarget(Scope scope) {
107109
this.scope = scope;
110+
if (scope == ServerEvent.Scope.CHANNEL) {
111+
this.channel = ServerContext.getRequestOwner().getEventChannel();
112+
} else if (scope == Scope.USER) {
113+
this.userKey =ServerContext.getRequestOwner().getUserKey();
114+
} else if (scope == Scope.SELF) {
115+
this.connID =ServerContext.getRequestOwner().getEventConnID();
116+
}
108117
}
109118

110119
/**
@@ -113,28 +122,24 @@ public EventTarget(Scope scope) {
113122
* @param scope
114123
* @param connID
115124
* @param channel
125+
* @param userKey
116126
*/
117-
public EventTarget(Scope scope, String connID, String channel) {
127+
public EventTarget(Scope scope, String connID, String channel, String userKey) {
118128
this.scope = scope;
119129
this.connID = connID;
120130
this.channel = channel;
131+
this.userKey = userKey;
121132
}
122133

123134
/**
124-
* returns true if a destination information is available.
125-
* Either connID or channel must contains a valid value.
135+
* returns true if a destination information can be resolved.
126136
* @return
127137
*/
128138
public boolean hasDestination() {
129-
return connID != null || channel != null;
130-
}
131-
132-
public void setConnID(String connID) {
133-
this.connID = connID;
134-
}
135-
136-
public void setChannel(String channel) {
137-
this.channel = channel;
139+
boolean rval = scope == ServerEvent.Scope.CHANNEL && !StringUtils.isEmpty(this.channel);
140+
rval = rval || (scope == ServerEvent.Scope.USER && !StringUtils.isEmpty(this.userKey));
141+
rval = rval || (scope == ServerEvent.Scope.SELF && !StringUtils.isEmpty(this.connID));
142+
return rval;
138143
}
139144

140145
public Scope getScope() {
@@ -145,9 +150,21 @@ public String getConnID() {
145150
return connID;
146151
}
147152

153+
public void setConnID(String connID) {
154+
this.connID = connID;
155+
}
156+
148157
public String getChannel() {
149158
return channel;
150159
}
160+
161+
public void setChannel(String channel) {
162+
this.channel = channel;
163+
}
164+
165+
public String getUserKey() {
166+
return userKey;
167+
}
151168
}
152169
}
153170

src/firefly/java/edu/caltech/ipac/firefly/data/ServerParams.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public class ServerParams {
128128
public static final String PROGRESS = "CmdProgress";
129129
public static final String SUB_BACKGROUND_SEARCH= "subBackgroundSearch";
130130
public static final String GET_STATUS= "status";
131+
public static final String REMOVE_JOB = "removeBgJob";
131132
public static final String CANCEL= "cancel";
132133
public static final String ADD_ID_TO_CRITERIA= "addIDToCriteria";
133134
public static final String CLEAN_UP= "cleanup";

src/firefly/java/edu/caltech/ipac/firefly/server/RequestOwner.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,15 @@ public void setRequestAgent(RequestAgent requestAgent) {
6666
if (requestAgent != null) {
6767
host = requestAgent.getHeader("host");
6868
referrer = requestAgent.getHeader("Referer");
69-
eventChannel = requestAgent.getHeader("FF-channel");
70-
eventConnID = requestAgent.getHeader("FF-connID");
69+
setWsConnInfo(requestAgent.getHeader("FF-connID"), requestAgent.getHeader("FF-channel"));
7170
}
7271
}
7372

73+
public void setWsConnInfo(String connID, String channel) {
74+
eventConnID = connID;
75+
eventChannel = channel;
76+
}
77+
7478
public WorkspaceManager getWsManager() {
7579
if (wsManager == null) {
7680
getUserInfo();

src/firefly/java/edu/caltech/ipac/firefly/server/ServerCommandAccess.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ private static void initCommand() {
7272
_cmdMap.put(ServerParams.GET_ENUM_VALUES, new SearchServerCommands.GetEnumValues());
7373
_cmdMap.put(ServerParams.SUB_BACKGROUND_SEARCH, new SearchServerCommands.SubmitBackgroundSearch());
7474
_cmdMap.put(ServerParams.GET_STATUS, new SearchServerCommands.GetStatus());
75+
_cmdMap.put(ServerParams.REMOVE_JOB, new SearchServerCommands.RemoveBgJob());
7576
_cmdMap.put(ServerParams.CANCEL, new SearchServerCommands.Cancel());
7677
_cmdMap.put(ServerParams.ADD_ID_TO_CRITERIA, new SearchServerCommands.AddIDToPushCriteria());
7778
_cmdMap.put(ServerParams.CLEAN_UP, new SearchServerCommands.CleanUp());

src/firefly/java/edu/caltech/ipac/firefly/server/events/FluxAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public FluxAction(String type) {
2020
this(type, new JSONObject());
2121
}
2222

23-
public FluxAction(String type , JSONObject payload) {
23+
public FluxAction(String type , Object payload) {
2424
root = new JSONObject();
2525
root.put(TYPE, type);
2626
root.put(PAYLOAD, payload);

src/firefly/java/edu/caltech/ipac/firefly/server/events/ServerEventManager.java

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,50 +32,57 @@ public class ServerEventManager {
3232
private static long deliveredEventCnt;
3333

3434

35-
36-
public static void fireAction(FluxAction action) { fireJsonAction(action.toString(), ServerEvent.Scope.SELF,null);
37-
}
38-
39-
public static void fireAction(FluxAction action, String channel) {
40-
fireJsonAction(action.toString(), ServerEvent.Scope.CHANNEL, channel);
35+
/**
36+
* Send this action to the calling client, i.e Scope.SELF.
37+
* @param action
38+
*/
39+
public static void fireAction(FluxAction action) {
40+
fireAction(action, ServerEvent.Scope.SELF);
4141
}
4242

43+
/**
44+
* Send this action to the calling client, i.e Scope.SELF.
45+
* @param action
46+
*/
4347
public static void fireAction(FluxAction action, ServerEvent.Scope scope) {
44-
fireJsonAction(action.toString(), scope, null);
48+
fireJsonAction(action.toString(), scope);
4549
}
4650

47-
public static void fireJsonAction(String actionStr, String channel) {
48-
fireJsonAction(actionStr, ServerEvent.Scope.CHANNEL, channel);
51+
/**
52+
* Send this action to a specific client based on the given target.
53+
* @param action
54+
* @param target
55+
*/
56+
public static void fireAction(FluxAction action, ServerEvent.EventTarget target) {
57+
fireJsonAction(action.toString(), target);
4958
}
5059

51-
public static void fireJsonAction(String actionStr, ServerEvent.Scope scope, String channel) {
52-
ServerEvent sev;
53-
if (channel!=null) {
54-
ServerEvent.EventTarget t= new ServerEvent.EventTarget(ServerEvent.Scope.CHANNEL,null,channel);
55-
sev = new ServerEvent(Name.ACTION, t, ServerEvent.DataType.JSON, actionStr);
56-
}
57-
else {
58-
sev = new ServerEvent(Name.ACTION, scope, ServerEvent.DataType.JSON, actionStr);
59-
}
60-
60+
/**
61+
* Send this JSON string action to the client based on the given scope
62+
* @param actionStr
63+
* @param scope
64+
*/
65+
public static void fireJsonAction(String actionStr, ServerEvent.Scope scope) {
66+
ServerEvent sev = new ServerEvent(Name.ACTION, scope, ServerEvent.DataType.JSON, actionStr);
6167
ServerEventManager.fireEvent(sev);
6268
}
6369

64-
70+
/**
71+
* Send this JSON string action to a specific client based on the given target.
72+
* @param actionStr
73+
* @param target
74+
*/
75+
public static void fireJsonAction(String actionStr, ServerEvent.EventTarget target) {
76+
ServerEvent sev = new ServerEvent(Name.ACTION, target, ServerEvent.DataType.JSON, actionStr);
77+
ServerEventManager.fireEvent(sev);
78+
}
6579

6680

6781

6882
public static void fireEvent(ServerEvent sev) {
69-
if (sev == null || sev.getTarget() == null) {
83+
if (sev == null || sev.getTarget() == null || !sev.getTarget().hasDestination()) {
7084
LOG.warn("Something is wrong with this ServerEvent: " + String.valueOf(sev));
7185
} else {
72-
if (!sev.getTarget().hasDestination()) {
73-
if (sev.getTarget().getScope() == ServerEvent.Scope.CHANNEL) {
74-
sev.getTarget().setChannel(ServerContext.getRequestOwner().getEventChannel());
75-
} else {
76-
sev.getTarget().setConnID(ServerContext.getRequestOwner().getEventConnID());
77-
}
78-
}
7986
eventWorker.deliver(sev);
8087
}
8188
}

src/firefly/java/edu/caltech/ipac/firefly/server/events/ServerEventQueue.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ public class ServerEventQueue {
3131
private final EventConnector eventTerminal;
3232
private String connID;
3333
private String channel;
34+
private String userKey;
3435

35-
public ServerEventQueue(String connID, String channel, EventConnector terminal) {
36+
public ServerEventQueue(String connID, String channel, String userKey, EventConnector terminal) {
3637
this.connID = connID;
3738
this.channel = channel;
39+
this.userKey = userKey;
3840
this.eventTerminal = terminal;
39-
4041
}
4142

4243
public static String convertToJson(ServerEvent ev) {
@@ -92,6 +93,8 @@ public static ServerEvent parseJsonEvent(String message) {
9293

9394
public String getConnID() { return connID; }
9495

96+
public String getUserKey() { return userKey; }
97+
9598
public void putEvent(ServerEvent ev) throws Exception{
9699
if (eventTerminal ==null){
97100
throw new IllegalStateException("Event terminal is null.. should remove this queue.");
@@ -127,6 +130,8 @@ public boolean matches(ServerEvent sEvent) {
127130
ServerEvent.Scope scope = sEvent.getTarget().getScope();
128131
if (scope == ServerEvent.Scope.CHANNEL) {
129132
return !StringUtils.isEmpty(evTarget.getChannel()) && evTarget.getChannel().equals(channel);
133+
} else if (scope == ServerEvent.Scope.USER){
134+
return !StringUtils.isEmpty(evTarget.getUserKey()) && evTarget.getUserKey().equals(userKey);
130135
} else if (scope == ServerEvent.Scope.SELF){
131136
return !StringUtils.isEmpty(evTarget.getConnID()) && evTarget.getConnID().equals(connID);
132137
} else if (scope == ServerEvent.Scope.WORLD){

0 commit comments

Comments
 (0)