public <T> void request(UUID uuid, DataKey<T> key) { try { ByteArrayDataOutput data = ByteStreams.newDataOutput(); DataStreamUtils.writeUUID(data, uuid); DataStreamUtils.writeDataKey(data, key); RedisBungee.getApi().sendChannelMessage(CHANNEL_DATA_REQUEST, Base64.getEncoder().encodeToString(data.toByteArray())); redisBungeeAPIError = false; } catch (RuntimeException ex) { if (!redisBungeeAPIError) { logger.log(Level.WARNING, "Error using RedisBungee API", ex); redisBungeeAPIError = true; } } catch (Throwable th) { BungeeTabListPlus.getInstance().getLogger().log(Level.SEVERE, "Failed to request data", th); } }
private <T> void updateData(UUID uuid, DataKey<T> key, T value) { try { ByteArrayDataOutput data = ByteStreams.newDataOutput(); DataStreamUtils.writeUUID(data, uuid); DataStreamUtils.writeDataKey(data, key); data.writeBoolean(value == null); if (value != null) { typeRegistry.getTypeAdapter(key.getType()).write(data, value); } RedisBungee.getApi().sendChannelMessage(CHANNEL_DATA_UPDATE, Base64.getEncoder().encodeToString(data.toByteArray())); } catch (RuntimeException ex) { BungeeTabListPlus.getInstance().getLogger().log(Level.WARNING, "RedisBungee Error", ex); } catch (Throwable th) { BungeeTabListPlus.getInstance().getLogger().log(Level.SEVERE, "Failed to send data", th); } }
void requestMissingData() throws IOException { synchronized (this) { if (requestAll) { Server connection = getConnection(); if (connection != null) { List<DataKey<?>> keys = new ArrayList<>(getQueriedKeys()); ByteArrayDataOutput data = ByteStreams.newDataOutput(); data.writeByte(this instanceof PlayerBridgeDataCache ? BridgeProtocolConstants.MESSAGE_ID_REQUEST_DATA : BridgeProtocolConstants.MESSAGE_ID_REQUEST_DATA_SERVER); data.writeInt(connectionId); data.writeInt(nextOutgoingMessageId++); data.writeInt(keys.size()); for (DataKey<?> key : keys) { DataStreamUtils.writeDataKey(data, key); data.writeInt(idMap.getNetId(key)); } byte[] message = data.toByteArray(); messagesPendingConfirmation.add(message); lastMessageSent = System.currentTimeMillis(); connection.sendData(BridgeProtocolConstants.CHANNEL, message); } requestAll = false; } } } }
@Override protected <V> void onMissingData(DataKey<V> key) { super.onMissingData(key); try { synchronized (this) { Server connection = getConnection(); if (connection != null) { ByteArrayDataOutput data = ByteStreams.newDataOutput(); data.writeByte(this instanceof PlayerBridgeDataCache ? BridgeProtocolConstants.MESSAGE_ID_REQUEST_DATA : BridgeProtocolConstants.MESSAGE_ID_REQUEST_DATA_SERVER); data.writeInt(connectionId); data.writeInt(nextOutgoingMessageId++); data.writeInt(1); DataStreamUtils.writeDataKey(data, key); data.writeInt(idMap.getNetId(key)); byte[] message = data.toByteArray(); messagesPendingConfirmation.add(message); lastMessageSent = System.currentTimeMillis(); connection.sendData(BridgeProtocolConstants.CHANNEL, message); } else { requestAll = true; } } } catch (Throwable th) { rlExecutor.execute(() -> { plugin.getLogger().log(Level.SEVERE, "Unexpected exception", th); }); requestAll = true; } }