private static org.kaaproject.kaa.common.endpoint.gen.LogDeliveryStatus convert( LogDeliveryStatus source) { if (source == null) { return null; } return new org.kaaproject.kaa.common.endpoint.gen.LogDeliveryStatus( source.getRequestId(), convert(source.getResult()), convert(source.getErrorCode())); }
@Override public ClientSync decode(byte[] data) throws PlatformEncDecException { ClientSync sync = super.decode(data); sync.setUseConfigurationRawSchema(true); return sync; } }
@Override public byte[] encode(ServerSync sync) throws PlatformEncDecException { if (sync == null) { return null; } LOG.trace("Encoding server sync {}", sync); SyncResponse response = convert(sync); LOG.trace("Encoded server sync {}", response); try { byte[] data = serverSyncConverter.toByteArray(response); if (LOG.isTraceEnabled()) { LOG.trace("Encoded avro data {}", Arrays.toString(data)); } return data; } catch (IOException exception) { throw new PlatformEncDecException(exception); } } }
private static ProfileSyncResponse convert(ProfileServerSync profileSyncResponse) { if (profileSyncResponse == null) { return null; } return new ProfileSyncResponse(convert(profileSyncResponse.getResponseStatus())); }
private static LogSyncResponse convert(LogServerSync source) { if (source == null) { return null; } LogSyncResponse sync = new LogSyncResponse(); List<org.kaaproject.kaa.common.endpoint.gen.LogDeliveryStatus> statuses = new ArrayList<>(); for (LogDeliveryStatus status : source.getDeliveryStatuses()) { statuses.add(convert(status)); } sync.setDeliveryStatuses(statuses); return sync; }
@Override public ClientSync decode(byte[] data) throws PlatformEncDecException { try { if (LOG.isTraceEnabled()) { LOG.trace("Decoding avro data {}", Arrays.toString(data)); } SyncRequest source = clientSyncConverter.fromByteArray(data); LOG.trace("Decoding client sync {}", source); if (source == null) { return null; } ClientSync sync = convert(source); sync.setUseConfigurationRawSchema(false); LOG.trace("Decoded client sync {}", sync); return sync; } catch (IOException exception) { throw new PlatformEncDecException(exception); } }
/** * Converts Avro {@link SyncRequest} to {@link ClientSync}. * * @param source the avro structure * @return the client sync */ public static ClientSync convert(SyncRequest source) { ClientSync dest = new ClientSync(); dest.setRequestId(source.getRequestId()); dest.setClientSyncMetaData(convert(source.getSyncRequestMetaData())); dest.setBootstrapSync(convert(source.getBootstrapSyncRequest())); dest.setProfileSync(convert(source.getProfileSyncRequest())); dest.setConfigurationSync(convert(source.getConfigurationSyncRequest())); dest.setNotificationSync(convert(source.getNotificationSyncRequest())); dest.setEventSync(convert(source.getEventSyncRequest())); dest.setUserSync(convert(source.getUserSyncRequest())); dest.setLogSync(convert(source.getLogSyncRequest())); return dest; }
private static BootstrapSyncResponse convert(BootstrapServerSync bootstrapSync) { if (bootstrapSync == null) { return null; } return new BootstrapSyncResponse( bootstrapSync.getRequestId(), convert(bootstrapSync.getProtocolList())); }
private static BootstrapClientSync convert(BootstrapSyncRequest source) { if (source == null) { return null; } return new BootstrapClientSync(source.getRequestId(), convert(source.getSupportedProtocols())); }
/** * Converts {@link ServerSync} to Avro {@link SyncResponse}. * * @param source the server sync * @return the Avro sync response */ public static SyncResponse convert(ServerSync source) { SyncResponse sync = new SyncResponse(); sync.setRequestId(source.getRequestId()); sync.setStatus(convert(source.getStatus())); sync.setBootstrapSyncResponse(convert(source.getBootstrapSync())); sync.setRedirectSyncResponse(convert(source.getRedirectSync())); sync.setProfileSyncResponse(convert(source.getProfileSync())); sync.setConfigurationSyncResponse(convert(source.getConfigurationSync())); sync.setNotificationSyncResponse(convert(source.getNotificationSync())); sync.setEventSyncResponse(convert(source.getEventSync())); sync.setUserSyncResponse(convert(source.getUserSync())); sync.setLogSyncResponse(convert(source.getLogSync())); return sync; }
private static NotificationSyncResponse convert(NotificationServerSync source) { if (source == null) { return null; } NotificationSyncResponse sync = new NotificationSyncResponse(); sync.setResponseStatus(convert(source.getResponseStatus())); if (source.getAvailableTopics() != null) { List<Topic> topics = new ArrayList<>(source.getAvailableTopics().size()); for (org.kaaproject.kaa.server.sync.Topic topic : source.getAvailableTopics()) { topics.add(new Topic( topic.getIdAsLong(), topic.getName(), convert(topic.getSubscriptionType()))); } sync.setAvailableTopics(topics); } if (source.getNotifications() != null) { List<Notification> notifications = new ArrayList<>(source.getNotifications().size()); for (org.kaaproject.kaa.server.sync.Notification notification : source.getNotifications()) { notifications.add(new Notification( notification.getTopicIdAsLong(), convert(notification.getType()), notification.getUid(), notification.getSeqNumber(), notification.getBody())); } sync.setNotifications(notifications); } return sync; }
private static EventSyncResponse convert(EventServerSync source) { if (source == null) { return null; } EventSyncResponse sync = new EventSyncResponse(); if (source.getEventSequenceNumberResponse() != null) { sync.setEventSequenceNumberResponse(new EventSequenceNumberResponse( source.getEventSequenceNumberResponse().getSeqNum())); } if (source.getEvents() != null) { List<org.kaaproject.kaa.common.endpoint.gen.Event> events = new ArrayList<>( source.getEvents().size()); for (Event event : source.getEvents()) { events.add(convert(event)); } sync.setEvents(events); } if (source.getEventListenersResponses() != null) { List<EventListenersResponse> responses = new ArrayList<>( source.getEventListenersResponses().size()); for (org.kaaproject.kaa.server.sync.EventListenersResponse response : source.getEventListenersResponses()) { responses.add(new EventListenersResponse( response.getRequestId(), response.getListeners(), convert(response.getResult()))); } sync.setEventListenersResponses(responses); } return sync; }
private static EventClientSync convert(EventSyncRequest source) { if (source == null) { return null; } EventClientSync sync = new EventClientSync(); sync.setSeqNumberRequest(source.getEventSequenceNumberRequest() != null); if (source.getEvents() != null) { List<Event> events = new ArrayList<Event>(source.getEvents().size()); for (org.kaaproject.kaa.common.endpoint.gen.Event event : source.getEvents()) { events.add(convert(event)); } sync.setEvents(events); } if (source.getEventListenersRequests() != null) { List<EventListenersRequest> requests = new ArrayList<>( source.getEventListenersRequests().size()); for (org.kaaproject.kaa.common.endpoint.gen.EventListenersRequest request : source.getEventListenersRequests()) { requests.add(new EventListenersRequest( request.getRequestId(), request.getEventClassFQNs())); } sync.setEventListenersRequests(requests); } return sync; }
private static ConfigurationSyncResponse convert(ConfigurationServerSync source) { if (source == null) { return null; } ConfigurationSyncResponse sync = new ConfigurationSyncResponse(); sync.setConfDeltaBody(source.getConfDeltaBody()); sync.setConfSchemaBody(source.getConfSchemaBody()); sync.setResponseStatus(convert(source.getResponseStatus())); return sync; }
private static UserAttachResponse convert( org.kaaproject.kaa.server.sync.UserAttachResponse source) { UserAttachResponse response = new UserAttachResponse(); response.setResult(source.getResult() == SyncStatus.SUCCESS ? SyncResponseResultType.SUCCESS : SyncResponseResultType.FAILURE); response.setErrorCode(convert(source.getErrorCode())); response.setErrorReason(source.getErrorReason()); return response; }
sync.setUserAttachResponse(convert(source.getUserAttachResponse())); : source.getEndpointAttachResponses()) { responses.add(new EndpointAttachResponse( response.getRequestId(), response.getEndpointKeyHash(), convert(response .getResult()))); : source.getEndpointDetachResponses()) { responses.add(new EndpointDetachResponse( response.getRequestId(), convert(response.getResult())));
org.kaaproject.kaa.server.sync.Event localEvent; try { localEvent = AvroEncDec.convert(eventConverter.get().fromByteArray( event.getEndpointEvent().getEventData())); EndpointEvent endpointEvent = new EndpointEvent(
org.kaaproject.kaa.server.sync.Event eventSource = remoteEndpointEvent.getEvent().getEvent(); eventData = ByteBuffer.wrap( eventConverter.get().toByteArray(AvroEncDec.convert(eventSource))); org.kaaproject.kaa.server.common.thrift.gen.operations.EndpointEvent endpointEvent = new org.kaaproject.kaa.server.common.thrift.gen.operations.EndpointEvent(