本文整理汇总了Java中org.glassfish.jersey.media.sse.InboundEvent.getName方法的典型用法代码示例。如果您正苦于以下问题:Java InboundEvent.getName方法的具体用法?Java InboundEvent.getName怎么用?Java InboundEvent.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.jersey.media.sse.InboundEvent
的用法示例。
在下文中一共展示了InboundEvent.getName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onEvent
import org.glassfish.jersey.media.sse.InboundEvent; //导入方法依赖的package包/类
@Override
public void onEvent(InboundEvent inboundEvent) {
String eventName = inboundEvent.getName();
if (mainEventName.equals(eventName)) {
Optional<Response<T>> resp;
try {
resp = responseBuilder.buildResponse(inboundEvent.readData(), clazz, uri);
} catch (Exception e) {
sseObserver.onParseError(new ParseError(inboundEvent.getId(), e, inboundEvent.getRawData()));
return;
}
sseObserver.onEvent(resp.get());
} else {
sseObserver.onSignal(eventName);
}
}
示例2: onEvent
import org.glassfish.jersey.media.sse.InboundEvent; //导入方法依赖的package包/类
private void onEvent(InboundEvent inboundEvent) {
try {
lastEventTimestamp = System.currentTimeMillis();
String name = inboundEvent.getName();
String data = inboundEvent.readData();
logger.debug("Received '{}' event, data: {}", name, data);
if (!connected) {
logger.debug("Connected to streaming events");
connected = true;
listeners.forEach(listener -> listener.onConnected());
}
if (AUTH_REVOKED.equals(name)) {
logger.debug("API authorization has been revoked for access token: {}", data);
listeners.forEach(listener -> listener.onAuthorizationRevoked(data));
} else if (ERROR.equals(name)) {
logger.warn("Error occurred: {}", data);
listeners.forEach(listener -> listener.onError(data));
} else if (KEEP_ALIVE.equals(name)) {
logger.debug("Received message to keep connection alive");
} else if (OPEN.equals(name)) {
logger.debug("Event stream opened");
} else if (PUT.equals(name)) {
logger.debug("Data has changed (or initial data sent)");
lastReceivedTopLevelData = gson.fromJson(data, TopLevelStreamingData.class).getData();
listeners.forEach(listener -> listener.onNewTopLevelData(lastReceivedTopLevelData));
} else {
logger.debug("Received unhandled event with name '{}' and data '{}'", name, data);
}
} catch (Exception e) {
// catch exceptions here otherwise they will be swallowed by the implementation
logger.warn("An exception occurred while processing the inbound event", e);
}
}
示例3: eventSourceThree
import org.glassfish.jersey.media.sse.InboundEvent; //导入方法依赖的package包/类
void eventSourceThree()
{
eventSource = new EventSource(target) {
@Override
public void onEvent(InboundEvent inboundEvent) {
// if ("message-to-client".equals(inboundEvent.getName())) {
System.out.println(inboundEvent.getName() + "; "
+ inboundEvent.readData(String.class));
String eventName = inboundEvent.getName();
String message = inboundEvent.readData(String.class);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(IntentServiceSSE.this)
.setContentTitle(eventName)
.setContentText(message)
.setContentInfo(message)
.setSmallIcon(R.mipmap.shopping_basket_png)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(2, mBuilder.build());
}
};
}
示例4: handleNotificationThree
import org.glassfish.jersey.media.sse.InboundEvent; //导入方法依赖的package包/类
void handleNotificationThree()
{
Client client = ClientBuilder.newBuilder()
.register(SseFeature.class).build();
int endUserID = -1;
if(UtilityLogin.getEndUser(getBaseContext())!=null)
{
endUserID = UtilityLogin.getEndUser(getBaseContext()).getEndUserID();
}
else
{
return;
}
System.out.println("On Handle Intent : Handle Notification !");
String url = UtilityGeneral.getServiceURL(MyApplication.getAppContext()) + "/api/v1/EndUser/Notifications/" + String.valueOf(endUserID);
System.out.println("URL : " + url);
// logMessage("URL : " + url);
WebTarget target = client.target(url);
eventSourceThree = EventSource.target(target)
.reconnectingEvery(5,TimeUnit.SECONDS)
.build();
EventListener listener = new EventListener() {
@Override
public void onEvent(InboundEvent inboundEvent) {
System.out.println(inboundEvent.getName() + "; "
+ inboundEvent.readData(String.class));
String eventName = inboundEvent.getName();
String message = inboundEvent.readData(String.class);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(IntentServiceSSE.this)
.setContentTitle(eventName)
.setContentText(message)
.setContentInfo(message)
.setSmallIcon(R.mipmap.shopping_basket_png)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(2, mBuilder.build());
}
};
eventSourceThree.register(listener);
eventSourceThree.open();
}