本文整理汇总了Java中io.socket.client.Ack类的典型用法代码示例。如果您正苦于以下问题:Java Ack类的具体用法?Java Ack怎么用?Java Ack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Ack类属于io.socket.client包,在下文中一共展示了Ack类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: emitFrom
import io.socket.client.Ack; //导入依赖的package包/类
/**
* Private method used by {@link SailsSocket#request}
*
* @param request {@link SailsSocketRequest}
*/
private void emitFrom(Socket socket, SailsSocketRequest request) {
// Name of the appropriate socket.io listener on the server
// ( === the request method or "verb", e.g. 'get', 'post', 'put', etc. )
String sailsEndpoint = request.getMethod();
// Since Listener is embedded in request, retrieve it.
final SailsSocketResponse.Listener listener = request.getListener();
socket.emit(sailsEndpoint, request.toJSONObject(), new Ack() {
@Override
public void call(Object... args) {
// Send back jsonWebSocketResponse
if (listener != null) {
listener.onResponse(new JWR((JSONObject) args[0]));
}
}
});
}
开发者ID:joshuamarquez,项目名称:sails.io.java,代码行数:24,代码来源:SailsSocket.java
示例2: channelGet
import io.socket.client.Ack; //导入依赖的package包/类
public void channelGet(final CallbackEvent callback) {
mChannelSocket.emit("channel.get", new Ack() {
@Override
public void call(Object... args) {
JSONObject response = (JSONObject) args[0];
Log.d(TAG, response.toString() );
if (response.has("status")) {
try {
if ("ok".equalsIgnoreCase(response.getString("status"))) {
callback.call(response);
} else {
callback.call();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
}
开发者ID:xpush,项目名称:lib-xpush-android,代码行数:23,代码来源:ChannelCore.java
示例3: createAckFunction
import io.socket.client.Ack; //导入依赖的package包/类
private Ack createAckFunction(final SettableFuture<GenericOutcome> future) {
return new Ack() {
@Override
public void call(Object... objects) {
if (objects.length == 0 || objects[0] == null) {
future.set(new GenericOutcome(new GameLiftError(GameLiftErrorType.SERVICE_CALL_FAILED)));
}
boolean value = (boolean) objects[0];
if (value) {
future.set(new GenericOutcome());
} else {
future.set(new GenericOutcome(new GameLiftError(GameLiftErrorType.SERVICE_CALL_FAILED)));
}
}
};
}
开发者ID:BoxtrotStudio,项目名称:amazon-gamelift-serversdk-java,代码行数:19,代码来源:AuxProxyMessageSender.java
示例4: send
import io.socket.client.Ack; //导入依赖的package包/类
public void send(String msg, String guid) throws URISyntaxException, JSONException {
JSONObject json = new JSONObject();
json.put("text", msg);
json.put("guid", guid);
// Immediately insert message into list so that UI feels more responsive
// Unsent messages are given a different distinction
final Message m = new Message(msg, username, 1, chat_id, 1, 0);
messageList.add(m);
holderList.put(m, messageList.size() - 1);
runOnUiThread(new Runnable() {
@Override
public void run() {
mAdapter.notifyItemInserted(messageList.size() - 1);
recyclerView.scrollToPosition(mAdapter.getItemCount() - 1);
mAdapter.notifyDataSetChanged();
}
});
socket.emit("sendMessage", json, new Ack() {
@Override
public void call(Object... args) {
Log.w("sending message", args[0].toString());
}
});
}
开发者ID:kedarv,项目名称:pipette,代码行数:27,代码来源:Messaging.java
示例5: channelLeave
import io.socket.client.Ack; //导入依赖的package包/类
public void channelLeave(final CallbackEvent callback) {
mChannelSocket.emit("channel.leave", new Ack() {
@Override
public void call(Object... args) {
JSONObject response = (JSONObject) args[0];
if (response.has("status")) {
try {
if ("ok".equalsIgnoreCase(response.getString("status"))) {
callback.call();
} else {
if (response.has("message") && "ERR-NOTEXIST".equals(response.getString("message") ) ) {
callback.call();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
}
开发者ID:xpush,项目名称:lib-xpush-android,代码行数:24,代码来源:ChannelCore.java
示例6: eventGetPlayerVotes
import io.socket.client.Ack; //导入依赖的package包/类
@Override
public void eventGetPlayerVotes(Object... req) {
log("Got eventGetPlayerVotes");
// Interpret message.
// TODO: Should be an error object.
if (req[0] == null) return;
log("Compiling votes...");
JSONObject res = getPluginConfig().getPlayerVotes((JSONObject)req[0]);
log("Sending votes...");
SocketIOClient.emit("PlayerVotes", res, new Ack() {
@Override
public void call(Object... cb) {
}
});
}
开发者ID:yariplus,项目名称:minecraft-nodebb-integration,代码行数:20,代码来源:NodeBBIntegrationBukkit.java
示例7: onPlayerChat
import io.socket.client.Ack; //导入依赖的package包/类
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerChat(AsyncPlayerChatEvent event) {
if (SocketIOClient.disconnected()) return;
final String socketEvent = "eventPlayerChat";
JSONObject obj = new JSONObject();
try {
obj.put("name", event.getPlayer().getName());
obj.put("id", event.getPlayer().getUniqueId());
obj.put("message", event.getMessage());
obj.put("key", plugin.getPluginConfig().getForumAPIKey());
} catch (JSONException e) {
plugin.log("Error constructing JSON Object for " + socketEvent);
e.printStackTrace();
return;
}
SocketIOClient.emit(socketEvent, obj, new Ack() {
@Override
public void call(Object... args) {
}
});
}
开发者ID:yariplus,项目名称:minecraft-nodebb-integration,代码行数:24,代码来源:ListenerPlayerChat.java
示例8: _createAckFunction
import io.socket.client.Ack; //导入依赖的package包/类
private Ack _createAckFunction(final SettableFuture<DescribePlayerSessionsOutcome> future) {
return new Ack() {
@Override
public void call(Object... objects) {
if (objects.length == 0 || objects[0] == null) {
future.set(new DescribePlayerSessionsOutcome(new GameLiftError(GameLiftErrorType.SERVICE_CALL_FAILED)));
}
boolean value = (boolean) objects[0];
if (value) {
try {
Sdk.DescribePlayerSessionsResponse.Builder builder = Sdk.DescribePlayerSessionsResponse.newBuilder();
JsonFormat.parser().merge((String)objects[1], builder);
Sdk.DescribePlayerSessionsResponse response = builder.build();
DescribePlayerSessionsResult result = transformResponse(response);
future.set(new DescribePlayerSessionsOutcome(result));
} catch (InvalidProtocolBufferException e) {
future.set(new DescribePlayerSessionsOutcome(new GameLiftError(GameLiftErrorType.SERVICE_CALL_FAILED, e)));
}
} else {
future.set(new DescribePlayerSessionsOutcome(new GameLiftError(GameLiftErrorType.SERVICE_CALL_FAILED)));
}
}
};
}
开发者ID:BoxtrotStudio,项目名称:amazon-gamelift-serversdk-java,代码行数:31,代码来源:AuxProxyMessageSender.java
示例9: describePlayerSessions
import io.socket.client.Ack; //导入依赖的package包/类
public DescribePlayerSessionsOutcome describePlayerSessions(DescribePlayerSessionsRequest request) {
Sdk.DescribePlayerSessionsRequest.Builder builder = Sdk.DescribePlayerSessionsRequest.newBuilder();
if (request.getGameSessionId() != null) {
builder.setGameSessionId(request.getGameSessionId());
}
if (request.getNextToken() != null) {
builder.setNextToken(request.getNextToken());
}
if (request.getPlayerId() != null) {
builder.setPlayerId(request.getPlayerId());
}
if (request.getPlayerSessionId() != null) {
builder.setPlayerSessionId(request.getPlayerSessionId());
}
if (request.getPlayerSessionStatusFilter() != null) {
builder.setPlayerSessionStatusFilter(request.getPlayerSessionStatusFilter());
}
builder.setLimit(request.getLimit());
Sdk.DescribePlayerSessionsRequest message = builder.build();
SettableFuture<DescribePlayerSessionsOutcome> future = SettableFuture.create();
Ack ack = _createAckFunction(future);
return emitEvent(message, ack, future, DESCRIBE_PLAYER_SESSION_ERROR);
}
开发者ID:BoxtrotStudio,项目名称:amazon-gamelift-serversdk-java,代码行数:31,代码来源:AuxProxyMessageSender.java
示例10: emitEvent
import io.socket.client.Ack; //导入依赖的package包/类
public synchronized <T extends GenericOutcome> T emitEvent(Message message,
Ack ack,
SettableFuture<T> future,
T genericError) {
socket.emit(message.getDescriptorForType().getFullName(), ack, message.toByteArray());
try {
return future.get(30, TimeUnit.SECONDS);
} catch (Throwable e) {
genericError.setError(new GameLiftError(genericError.getError().getErrorType(), e));
return genericError;
}
}
开发者ID:BoxtrotStudio,项目名称:amazon-gamelift-serversdk-java,代码行数:14,代码来源:AuxProxyMessageSender.java
示例11: onPlayerQuit
import io.socket.client.Ack; //导入依赖的package包/类
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
String socketEvent = SocketIOClient.Events.onPlayerQuit;
SocketIOClient.emit(socketEvent, getPlayerQuitData(event.getPlayer()), new Ack() {
@Override
public void call(Object... args) {
}
});
}
开发者ID:yariplus,项目名称:minecraft-nodebb-integration,代码行数:10,代码来源:ListenerPlayerQuit.java
示例12: sendEvent
import io.socket.client.Ack; //导入依赖的package包/类
private static void sendEvent(final String socketEvent, final JSONObject data, final Doable res) {
// Send socket event to the forum.
SocketIOClient.emit(socketEvent, data, new Ack() {
@Override
public void call(Object... args) {
// We receive a callback form the forum with information about the primary linked user.
// First arg is an error object.
if (args[0] == null) {
// Construct response object.
if (args[1] != null) {
// Call the callback if it exists.
if (res != null) res.doit(args[1]);
} else {
Logger.log(socketEvent + " callback no response object found.");
}
} else {
Logger.log(socketEvent + " callback error.");
try {
Logger.log(((JSONObject) args[0]).getString("message"));
} catch (JSONException e) {
//TODO
e.printStackTrace();
}
}
}
});
}
开发者ID:yariplus,项目名称:minecraft-nodebb-integration,代码行数:32,代码来源:MinecraftServerEvents.java
示例13: gameListQuery
import io.socket.client.Ack; //导入依赖的package包/类
private void gameListQuery(JSONObject args, Consumer<JSONObject> callback) {
connection.emit(GAMELIST, args, (Ack) res -> argsToJSON(callback, res));
}
开发者ID:GoSuji,项目名称:Suji,代码行数:4,代码来源:Connection.java
示例14: onStartGameSession
import io.socket.client.Ack; //导入依赖的package包/类
void onStartGameSession(final String rawGameSession, Ack ack) {
debug("ServerState got the startGameSession signal. rawGameSession : " + rawGameSession);
if (!processReady) {
debug("Got a game session on inactive process. Sending false ack.");
ack.call(false);
return;
}
debug("Sending true ack.");
ack.call(true);
runAsync(new Runnable() {
@Override
public void run() {
try {
//Parse message
Sdk.GameSession.Builder builder = Sdk.GameSession.newBuilder();
JsonFormat.parser().merge(rawGameSession, builder);
Sdk.GameSession parsed = builder.build();
//Convert to model
GameSession session = new GameSession();
session.setName(parsed.getName());
session.setFleetId(parsed.getFleetId());
session.setGameSessionId(parsed.getGameSessionId());
session.setMaximumPlayerSessionCount(parsed.getGamePropertiesCount());
session.setGameProperties(new HashMap<String, String>());
for (int i = 0; i < parsed.getGamePropertiesCount(); i++) {
Sdk.GameProperty property = parsed.getGameProperties(i);
session.addGameProperty(property.getKey(), property.getValue());
}
//Save and invoke onGameSessionStarted
gameSessionId = session.getGameSessionId();
processParameters.gameSessionStarted(session);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
});
}
开发者ID:BoxtrotStudio,项目名称:amazon-gamelift-serversdk-java,代码行数:46,代码来源:ServerState.java
示例15: fetchConversations
import io.socket.client.Ack; //导入依赖的package包/类
public void fetchConversations() {
socket.emit("getAllChat", new Ack() {
@Override
public void call(Object... args) {
ObjectMapper mapper = new ObjectMapper();
try {
// Establish root node
JsonNode rootNode = mapper.readTree(args[0].toString());
Iterator<JsonNode> iterator = rootNode.elements();
while (iterator.hasNext()) {
int numPeople = 0;
HashMap<String, String> peopleMap = new HashMap<String, String>();
JsonNode chatThread = iterator.next();
long date = chatThread.get("lastUpdate").asLong();
Iterator<JsonNode> peopleIterator = chatThread.get("people").elements();
while(peopleIterator.hasNext()) {
numPeople++;
JsonNode person = peopleIterator.next();
String number = person.get("value").toString().replace("\"", "");
if(!number.contains("@")) {
number = String.format("(%s) %s-%s", number.substring(2, 5), number.substring(5, 8),
number.substring(8, 12));
}
String name = getContactName(getApplicationContext(), number);
if (name != null) {
peopleMap.put(number, name);
} else {
peopleMap.put(number, number);
}
}
ColorGenerator colorGenerator = ColorGenerator.MATERIAL; // or use DEFAULT
Chat chat = new Chat(chatThread.get("chat_id").asInt(), peopleMap, date, chatThread.get("guid").asText());
chat.setNumPeople(numPeople);
chat.setColor(colorGenerator.getColor(chat.getChatID()));
cList.add(chat);
Log.w("people", peopleMap.toString());
Log.w("getPeople", chat.getNumPeople() + "");
runOnUiThread(new Runnable() {
@Override
public void run() {
chatAdapter.notifyDataSetChanged();
}
});
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
chatAdapter.notifyDataSetChanged();
}
开发者ID:kedarv,项目名称:pipette,代码行数:54,代码来源:MainActivity.java
示例16: emit
import io.socket.client.Ack; //导入依赖的package包/类
public void emit(String event,Object[] args,Ack ack){
mSocket.emit(event, args, ack);
}
开发者ID:Mahabali,项目名称:Socket.io-Android-Chat,代码行数:4,代码来源:SocketIOService.java
示例17: emit
import io.socket.client.Ack; //导入依赖的package包/类
public void emit(String event,Object[] args,Ack ack){
socketServiceInterface.emit(event, args, ack);
}
开发者ID:Mahabali,项目名称:Socket.io-Android-Chat,代码行数:4,代码来源:AppSocketListener.java
示例18: run
import io.socket.client.Ack; //导入依赖的package包/类
@Override
public void run() {
if (SocketIOClient.connected()) {
final String socketEvent = ESocketEvent.SEND_SERVER_STATUS;
JSONObject obj = new JSONObject();
try {
obj.put("tps", server.getTPS());
obj.put("key", PluginConfig.instance.getForumAPIKey());
obj.put("players", server.getPlayerList());
obj.put("version", server.getVersion());
obj.put("name", server.getServerName());
obj.put("gametype", server.getWorldType());
obj.put("map", server.getWorldName());
obj.put("motd", server.getMotd());
obj.put("onlinePlayers", server.getOnlinePlayers());
obj.put("maxPlayers", server.getMaxPlayers());
obj.put("pluginList", server.getPluginList());
obj.put("icon", server.getServerIcon());
} catch (JSONException e) {
Logger.log("Error constructing JSON Object for " + socketEvent);
e.printStackTrace();
return;
}
Logger.log("Sending " + socketEvent);
SocketIOClient.emit(socketEvent, obj, new Ack() {
@Override
public void call(Object... args) {
Logger.log(args[0] == null ? "no errors" : "got error");
}
});
}
}
开发者ID:yariplus,项目名称:minecraft-nodebb-integration,代码行数:44,代码来源:TaskTick.java
示例19: safeCallback
import io.socket.client.Ack; //导入依赖的package包/类
/**
* Get callback from handler arguments.
*
* @param args Arguments.
* @return Callback or noop callback.
*/
public static Ack safeCallback(Object[] args) {
boolean hasCb = args != null && args.length > 0 && args[args.length - 1] instanceof Ack;
return hasCb ? (Ack)args[args.length - 1] : NOOP_CB;
}
开发者ID:apache,项目名称:ignite,代码行数:12,代码来源:AgentUtils.java
示例20: removeCallback
import io.socket.client.Ack; //导入依赖的package包/类
/**
* Remove callback from handler arguments.
*
* @param args Arguments.
* @return Arguments without callback.
*/
public static Object[] removeCallback(Object[] args) {
boolean hasCb = args != null && args.length > 0 && args[args.length - 1] instanceof Ack;
return hasCb ? Arrays.copyOf(args, args.length - 1) : args;
}
开发者ID:apache,项目名称:ignite,代码行数:12,代码来源:AgentUtils.java
注:本文中的io.socket.client.Ack类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论