This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8deb60e
commit c0a53c3
Showing
13 changed files
with
318 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
= Hawkular Feed Communications API | ||
|
||
This is used for the server to communication with its feeds over WebSockets. It also is used for UI clients to talk to the server as well (presumably for the UI to manage remote resources that are managed by feeds). | ||
|
||
This API (both requests and responses) is driven by JSON schemas so clients (both feed and UI) need not be Java in order to talk over this API to the Hawkular server. See the src/main/resources/schema folder. All schemas come with this Maven module's artifact jar inside the "schema" folder. If you have a non-Java client, you can generate your JSON based on those schemas. | ||
|
||
If your client is Java, you can use the Java API that also comes with the artifact jar. All JSON messages (requests and responses) have Java POJOs associated with the JSON schemas. These Java POJOs are auto-generated from the schemas. All POJOs are generated in the package "org.hawkular.feedcomm.api" with the name of the POJO being the name of the schema. For example, the schema NotificationMessage.schema.json will have an associated Java POJO autogenerated with the name org.hawkular.feedcomm.api.NotificationMessage. | ||
|
||
Because this API flows over WebSockets, multiple requests and responses may be sent and received to clients. Because of this, in order to make it easier on the client to deserialize incoming requests and responses, the messages that flow over the WebSocket connection are not merely the JSON-encoded data. Instead, the JSON-encoded data is prefixed with the name of the schema, optionally prefixed with the package name. For example, suppose NotificationMessage schema results in a JSON of the form: | ||
|
||
{noformat}{"message": "the msg here"}{noformat} | ||
|
||
The client receiving this message will actually receive the following data: | ||
|
||
{noformat}NotificationMessage={"message": "the msg here"}{noformat} | ||
|
||
It may optionally look like: | ||
|
||
{noformat}org.hawkular.feedcomm.api.NotificationMessage={"message": "the msg here"}{noformat} | ||
|
||
A Java client can use the utility org.hawkular.feedcomm.api.ApiDeserializer.deserialize() (passing in that string) to obtain the Java POJO that represents this notification message. A non-Java client can utilize the NotificationMessage.schema.json (note, the name of the schema is the same name as that prefix, minus any optional package name) in order to know how to deserialize the JSON message. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
modules/feed-comm/feed-comm-api/src/main/resources/schema/NotificationMessage.schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"type": "object", | ||
"extends": { | ||
"type": "object", | ||
"javaType": "org.hawkular.bus.common.BasicMessage" | ||
}, | ||
"javaType": "org.hawkular.feedcomm.api.NotificationMessage", | ||
"description": "An general notification message.", | ||
"additionalProperties": false, | ||
"properties": { | ||
"message": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["message"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...es/feed-comm/feed-comm-war/src/main/java/org/hawkular/feedcomm/ws/ConnectedUIClients.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright 2015 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hawkular.feedcomm.ws; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.ejb.ConcurrencyManagement; | ||
import javax.ejb.ConcurrencyManagementType; | ||
import javax.ejb.Lock; | ||
import javax.ejb.LockType; | ||
import javax.ejb.Singleton; | ||
import javax.ejb.Startup; | ||
import javax.websocket.Session; | ||
|
||
import org.hawkular.feedcomm.api.ApiDeserializer; | ||
import org.hawkular.feedcomm.api.NotificationMessage; | ||
|
||
/** | ||
* Maintains a runtime list of UI clients currently connected with this server. | ||
*/ | ||
@Startup | ||
@Singleton | ||
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER) | ||
public class ConnectedUIClients { | ||
|
||
// key=sessionID, value=UI client websocket session | ||
private Map<String, Session> sessions; | ||
|
||
@PostConstruct | ||
public void initialize() { | ||
MsgLogger.LOG.debugf("ConnectedUIClients has initialized"); | ||
this.sessions = new HashMap<>(); | ||
} | ||
|
||
@Lock(LockType.READ) | ||
public int getTotalSessions() { | ||
return this.sessions.size(); | ||
|
||
} | ||
|
||
@Lock(LockType.WRITE) | ||
public void addSession(Session newSession) { | ||
this.sessions.put(newSession.getId(), newSession); | ||
MsgLogger.LOG.infof("A UI client session has been added [%s]. There are now [%d] connected UI clients", | ||
newSession.getId(), this.sessions.size()); | ||
|
||
} | ||
|
||
@Lock(LockType.WRITE) | ||
public void removeSession(Session doomedSession) { | ||
Session removed = this.sessions.remove(doomedSession.getId()); | ||
if (removed != null) { | ||
MsgLogger.LOG.infof("A UI client session has been removed [%s]. There are now [%d] connected UI clients", | ||
removed.getId(), this.sessions.size()); | ||
} | ||
} | ||
|
||
@Lock(LockType.READ) | ||
public void sendNotificationMessageToAll(NotificationMessage notification) { | ||
String message = ApiDeserializer.toHawkularFormat(notification); | ||
MsgLogger.LOG.debugf("Sending notification message to all UI clients: [%s]", message); | ||
for (Session session : this.sessions.values()) { | ||
session.getAsyncRemote().sendText(message); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.