com.google.ipc.invalidation.external.client.InvalidationListener Java Examples
The following examples show how to use
com.google.ipc.invalidation.external.client.InvalidationListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InvalidationClientCore.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
/** * Constructs a client with state initialized from {@code marshalledState}. * * @param resources resources to use during execution * @param random a random number generator * @param clientType client type code * @param clientName application identifier for the client * @param config configuration for the client * @param applicationName name of the application using the library (for debugging/monitoring) * @param listener application callback */ public InvalidationClientCore(final SystemResources resources, Random random, int clientType, final byte[] clientName, ClientConfigP config, String applicationName, InvalidationClientState marshalledState, InvalidationListener listener) { this(resources, random, clientType, clientName, config, applicationName, marshalledState.getRunState(), marshalledState.getRegistrationManagerState(), marshalledState.getProtocolHandlerState(), marshalledState.getStatisticsState(), listener); // Unmarshall. if (marshalledState.hasClientToken()) { clientToken = marshalledState.getClientToken(); } if (marshalledState.hasNonce()) { nonce = marshalledState.getNonce(); } this.shouldSendRegistrations = marshalledState.getShouldSendRegistrations(); this.lastMessageSendTimeMs = marshalledState.getLastMessageSendTimeMs(); this.isOnline = marshalledState.getIsOnline(); createSchedulingTasks(marshalledState); // We register with the network after unmarshalling our isOnline value. This is because when // we register with the network, it may give us a new value for isOnline. If we unmarshalled // after registering, then we would clobber the new value with the old marshalled value, which // is wrong. registerWithNetwork(resources); logger.info("Created client: %s", this); }
Example #2
Source File: AndroidInvalidationListenerIntentMapper.java From 365browser with Apache License 2.0 | 6 votes |
/** * Handles an invalidation-related listener {@code upcall} by dispatching to the appropriate * method on an instance of {@link InvalidationListener}. */ private void onInvalidateUpcall(InvalidateUpcall invalidate, InvalidationListener listener) { AckHandle ackHandle = AckHandle.newInstance(invalidate.getAckHandle().getByteArray()); if (invalidate.getNullableInvalidation() != null) { listener.invalidate(client, ProtoWrapperConverter.convertFromInvalidationProto(invalidate.getNullableInvalidation()), ackHandle); } else if (invalidate.hasInvalidateAll()) { listener.invalidateAll(client, ackHandle); } else if (invalidate.getNullableInvalidateUnknown() != null) { listener.invalidateUnknownVersion(client, ProtoWrapperConverter.convertFromObjectIdProto(invalidate.getNullableInvalidateUnknown()), ackHandle); } else { throw new RuntimeException("Invalid invalidate upcall: " + invalidate); } }
Example #3
Source File: InvalidationClientCore.java From 365browser with Apache License 2.0 | 6 votes |
/** * Constructs a client. * * @param resources resources to use during execution * @param random a random number generator * @param clientType client type code * @param clientName application identifier for the client * @param config configuration for the client * @param applicationName name of the application using the library (for debugging/monitoring) * @param regManagerState marshalled registration manager state, if any * @param protocolHandlerState marshalled protocol handler state, if any * @param listener application callback */ private InvalidationClientCore(final SystemResources resources, Random random, int clientType, final byte[] clientName, ClientConfigP config, String applicationName, RunStateP ticlRunState, RegistrationManagerStateP regManagerState, ProtocolHandlerState protocolHandlerState, StatisticsState statisticsState, InvalidationListener listener) { this.resources = Preconditions.checkNotNull(resources); this.random = random; this.logger = Preconditions.checkNotNull(resources.getLogger()); this.internalScheduler = resources.getInternalScheduler(); this.storage = resources.getStorage(); this.config = config; this.ticlState = (ticlRunState == null) ? new RunState() : new RunState(ticlRunState); this.smearer = new Smearer(random, this.config.getSmearPercent()); this.applicationClientId = ApplicationClientIdP.create(clientType, new Bytes(clientName)); this.listener = listener; this.statistics = (statisticsState != null) ? Statistics.deserializeStatistics(resources.getLogger(), statisticsState.getCounter()) : new Statistics(); this.registrationManager = new RegistrationManager(logger, statistics, digestFn, regManagerState); this.protocolHandler = new ProtocolHandler(config.getProtocolHandlerConfig(), resources, smearer, statistics, clientType, applicationName, this, protocolHandlerState); }
Example #4
Source File: AndroidInvalidationListenerIntentMapper.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
/** * Handles an invalidation-related listener {@code upcall} by dispatching to the appropriate * method on an instance of {@link #listenerClass}. */ private void onInvalidateUpcall(ListenerUpcall upcall, InvalidationListener listener) { InvalidateUpcall invalidate = upcall.getInvalidate(); AckHandle ackHandle = AckHandle.newInstance(invalidate.getAckHandle().toByteArray()); if (invalidate.hasInvalidation()) { listener.invalidate(client, ProtoConverter.convertFromInvalidationProto(invalidate.getInvalidation()), ackHandle); } else if (invalidate.hasInvalidateAll()) { listener.invalidateAll(client, ackHandle); } else if (invalidate.hasInvalidateUnknown()) { listener.invalidateUnknownVersion(client, ProtoConverter.convertFromObjectIdProto(invalidate.getInvalidateUnknown()), ackHandle); } else { throw new RuntimeException("Invalid invalidate upcall: " + invalidate); } }
Example #5
Source File: InvalidationClientCore.java From 365browser with Apache License 2.0 | 6 votes |
/** * Constructs a client with state initialized from {@code marshalledState}. * * @param resources resources to use during execution * @param random a random number generator * @param clientType client type code * @param clientName application identifier for the client * @param config configuration for the client * @param applicationName name of the application using the library (for debugging/monitoring) * @param listener application callback */ public InvalidationClientCore(final SystemResources resources, Random random, int clientType, final byte[] clientName, ClientConfigP config, String applicationName, InvalidationClientState marshalledState, InvalidationListener listener) { this(resources, random, clientType, clientName, config, applicationName, marshalledState.getRunState(), marshalledState.getRegistrationManagerState(), marshalledState.getProtocolHandlerState(), marshalledState.getStatisticsState(), listener); // Unmarshall. if (marshalledState.hasClientToken()) { clientToken = marshalledState.getClientToken(); } if (marshalledState.hasNonce()) { nonce = marshalledState.getNonce(); } this.shouldSendRegistrations = marshalledState.getShouldSendRegistrations(); this.lastMessageSendTimeMs = marshalledState.getLastMessageSendTimeMs(); this.isOnline = marshalledState.getIsOnline(); createSchedulingTasks(marshalledState); // We register with the network after unmarshalling our isOnline value. This is because when // we register with the network, it may give us a new value for isOnline. If we unmarshalled // after registering, then we would clobber the new value with the old marshalled value, which // is wrong. registerWithNetwork(resources); logger.info("Created client: %s", this); }
Example #6
Source File: AndroidClientProxy.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
/** * Creates a new InvalidationClient instance that the proxy will delegate requests to and listen * for events from. */ // Overridden by tests to inject mock clients or for listener interception InvalidationClient createClient(SystemResources resources, int clientType, byte[] clientName, String applicationName, InvalidationListener listener, ClientConfigP config) { // We always use C2DM, so set the channel-supports-offline-delivery bit on our config. final ClientConfigP.Builder configBuilder; if (config == null) { configBuilder = InvalidationClientCore.createConfig(); } else { configBuilder = ClientConfigP.newBuilder(config); } configBuilder.setChannelSupportsOfflineDelivery(true); config = configBuilder.build(); Random random = new Random(resources.getInternalScheduler().getCurrentTimeMs()); return new InvalidationClientImpl(resources, random, clientType, clientName, config, applicationName, listener); }
Example #7
Source File: InvalidationClientCore.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
/** * Constructs a client with state initialized from {@code marshalledState}. * * @param resources resources to use during execution * @param random a random number generator * @param clientType client type code * @param clientName application identifier for the client * @param config configuration for the client * @param applicationName name of the application using the library (for debugging/monitoring) * @param listener application callback */ public InvalidationClientCore(final SystemResources resources, Random random, int clientType, final byte[] clientName, ClientConfigP config, String applicationName, InvalidationClientState marshalledState, InvalidationListener listener) { this(resources, random, clientType, clientName, config, applicationName, marshalledState.getRunState(), marshalledState.getRegistrationManagerState(), marshalledState.getProtocolHandlerState(), marshalledState.getStatisticsState(), listener); // Unmarshall. if (marshalledState.hasClientToken()) { clientToken = marshalledState.getClientToken(); } if (marshalledState.hasNonce()) { nonce = marshalledState.getNonce(); } this.shouldSendRegistrations = marshalledState.getShouldSendRegistrations(); this.lastMessageSendTimeMs = marshalledState.getLastMessageSendTimeMs(); this.isOnline = marshalledState.getIsOnline(); createSchedulingTasks(marshalledState); // We register with the network after unmarshalling our isOnline value. This is because when // we register with the network, it may give us a new value for isOnline. If we unmarshalled // after registering, then we would clobber the new value with the old marshalled value, which // is wrong. registerWithNetwork(resources); logger.info("Created client: %s", this); }
Example #8
Source File: AndroidInvalidationListenerIntentMapper.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
/** * Handles an invalidation-related listener {@code upcall} by dispatching to the appropriate * method on an instance of {@link #listenerClass}. */ private void onInvalidateUpcall(ListenerUpcall upcall, InvalidationListener listener) { InvalidateUpcall invalidate = upcall.getInvalidate(); AckHandle ackHandle = AckHandle.newInstance(invalidate.getAckHandle().toByteArray()); if (invalidate.hasInvalidation()) { listener.invalidate(client, ProtoConverter.convertFromInvalidationProto(invalidate.getInvalidation()), ackHandle); } else if (invalidate.hasInvalidateAll()) { listener.invalidateAll(client, ackHandle); } else if (invalidate.hasInvalidateUnknown()) { listener.invalidateUnknownVersion(client, ProtoConverter.convertFromObjectIdProto(invalidate.getInvalidateUnknown()), ackHandle); } else { throw new RuntimeException("Invalid invalidate upcall: " + invalidate); } }
Example #9
Source File: AndroidClientProxy.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
/** * Creates a new InvalidationClient instance that the proxy will delegate requests to and listen * for events from. */ // Overridden by tests to inject mock clients or for listener interception InvalidationClient createClient(SystemResources resources, int clientType, byte[] clientName, String applicationName, InvalidationListener listener, ClientConfigP config) { // We always use C2DM, so set the channel-supports-offline-delivery bit on our config. final ClientConfigP.Builder configBuilder; if (config == null) { configBuilder = InvalidationClientCore.createConfig(); } else { configBuilder = ClientConfigP.newBuilder(config); } configBuilder.setChannelSupportsOfflineDelivery(true); config = configBuilder.build(); Random random = new Random(resources.getInternalScheduler().getCurrentTimeMs()); return new InvalidationClientImpl(resources, random, clientType, clientName, config, applicationName, listener); }
Example #10
Source File: InvalidationTestListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void invalidateAll(InvalidationClient client, AckHandle ackHandle) { InvalidationListener listener = getListener(client); logger.fine("Received INVALIDATE_ALL for %s: %s", getClientKey(client), listener); if (listener != null) { listener.invalidateAll(client, ackHandle); } }
Example #11
Source File: InvalidationTestListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void informError(InvalidationClient client, ErrorInfo errorInfo) { InvalidationListener listener = getListener(client); logger.fine("Received INFORM_ERROR for %s: %s", getClientKey(client), listener); if (listener != null) { listener.informError(client, errorInfo); } }
Example #12
Source File: InvalidationTestListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void reissueRegistrations(InvalidationClient client, byte[] prefix, int prefixLength) { InvalidationListener listener = getListener(client); logger.fine("Received REISSUE_REGISTRATIONS for %s: %s", getClientKey(client), listener); if (listener != null) { listener.reissueRegistrations(client, prefix, prefixLength); } }
Example #13
Source File: InvalidationTestListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void informRegistrationFailure( InvalidationClient client, ObjectId objectId, boolean isTransient, String errorMessage) { InvalidationListener listener = getListener(client); logger.fine("Received INFORM_REGISTRATION_FAILURE for %s: %s", getClientKey(client), listener); if (listener != null) { listener.informRegistrationFailure(client, objectId, isTransient, errorMessage); } }
Example #14
Source File: InvalidationTestListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void informRegistrationStatus( InvalidationClient client, ObjectId objectId, RegistrationState regState) { InvalidationListener listener = getListener(client); logger.fine("Received INFORM_REGISTRATION_STATUS for %s: %s", getClientKey(client), listener); if (listener != null) { listener.informRegistrationStatus(client, objectId, regState); } }
Example #15
Source File: InvalidationTestListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void ready(InvalidationClient client) { InvalidationListener listener = getListener(client); logger.fine("Received READY for %s: %s", getClientKey(client), listener); if (listener != null) { listener.ready(client); } }
Example #16
Source File: InvalidationClientImpl.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
public InvalidationClientImpl(final SystemResources resources, Random random, int clientType, final byte[] clientName, ClientConfigP config, String applicationName, InvalidationListener listener) { super( // We will make Storage a SafeStorage after the constructor call. It's not possible to // construct a new resources around the existing components and pass that to super(...) // because then subsequent calls on the first resources object (e.g., start) would not // affect the new resources object that the Ticl would be using. resources, // Pass basic parameters through unmodified. random, clientType, clientName, config, applicationName, // Wrap the listener in a CheckingInvalidationListener to enforce appropriate threading. new CheckingInvalidationListener(listener, resources.getInternalScheduler(), resources.getListenerScheduler(), resources.getLogger()) ); // End super. // Make Storage safe. this.storage = new SafeStorage(resources.getStorage()); this.storage.setSystemResources(resources); // CheckingInvalidationListener needs the statistics object created by our super() call, so // we can't provide it at construction-time (since it hasn't been created yet). ((CheckingInvalidationListener) this.listener).setStatistics(statistics); }
Example #17
Source File: AndroidInvalidationListenerStub.java From 365browser with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private Class<? extends InvalidationListener> getListenerClass() { try { // Find the listener class that the application wants to use to receive upcalls. return (Class<? extends InvalidationListener>) Class.forName(new AndroidTiclManifest(this).getListenerClass()); } catch (ClassNotFoundException exception) { throw new RuntimeException("Invalid listener class", exception); } }
Example #18
Source File: CheckingInvalidationListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
CheckingInvalidationListener(InvalidationListener delegate, Scheduler internalScheduler, Scheduler listenerScheduler, Logger logger) { this.delegate = Preconditions.checkNotNull(delegate, "Delegate cannot be null"); this.internalScheduler = Preconditions.checkNotNull(internalScheduler, "Internal scheduler cannot be null"); this.listenerScheduler = Preconditions.checkNotNull(listenerScheduler, "Listener scheduler cannot be null"); this.logger = Preconditions.checkNotNull(logger, "Logger cannot be null"); }
Example #19
Source File: InvalidationClientCore.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** Handles incoming registration statuses. */ private void handleRegistrationStatus(List<RegistrationStatus> regStatusList) { Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread"); List<Boolean> localProcessingStatuses = registrationManager.handleRegistrationStatus(regStatusList); Preconditions.checkState(localProcessingStatuses.size() == regStatusList.size(), "Not all registration statuses were processed"); // Inform app about the success or failure of each registration based // on what the registration manager has indicated. for (int i = 0; i < regStatusList.size(); ++i) { RegistrationStatus regStatus = regStatusList.get(i); boolean wasSuccess = localProcessingStatuses.get(i); logger.fine("Process reg status: %s", regStatus); ObjectId objectId = ProtoConverter.convertFromObjectIdProto( regStatus.getRegistration().getObjectId()); if (wasSuccess) { // Server operation was both successful and agreed with what the client wanted. OpType regOpType = regStatus.getRegistration().getOpType(); InvalidationListener.RegistrationState regState = convertOpTypeToRegState(regOpType); listener.informRegistrationStatus(InvalidationClientCore.this, objectId, regState); } else { // Server operation either failed or disagreed with client's intent (e.g., successful // unregister, but the client wanted a registration). String description = CommonProtos2.isSuccess(regStatus.getStatus()) ? "Registration discrepancy detected" : regStatus.getStatus().getDescription(); boolean isPermanent = CommonProtos2.isPermanentFailure(regStatus.getStatus()); listener.informRegistrationFailure(InvalidationClientCore.this, objectId, !isPermanent, description); } } }
Example #20
Source File: InvalidationClientCore.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * Converts an operation type {@code regOpType} to a * {@code InvalidationListener.RegistrationState}. */ private static InvalidationListener.RegistrationState convertOpTypeToRegState( RegistrationP.OpType regOpType) { InvalidationListener.RegistrationState regState = regOpType == RegistrationP.OpType.REGISTER ? InvalidationListener.RegistrationState.REGISTERED : InvalidationListener.RegistrationState.UNREGISTERED; return regState; }
Example #21
Source File: InvalidationTestListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void invalidateUnknownVersion( InvalidationClient client, ObjectId objectId, AckHandle ackHandle) { InvalidationListener listener = getListener(client); logger.fine("Received INVALIDATE_UNKNOWN_VERSION for %s: %s", getClientKey(client), listener); if (listener != null) { listener.invalidateUnknownVersion(client, objectId, ackHandle); } }
Example #22
Source File: InvalidationClientCore.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * Constructs a client. * * @param resources resources to use during execution * @param random a random number generator * @param clientType client type code * @param clientName application identifier for the client * @param config configuration for the client * @param applicationName name of the application using the library (for debugging/monitoring) * @param regManagerState marshalled registration manager state, if any * @param protocolHandlerState marshalled protocol handler state, if any * @param listener application callback */ private InvalidationClientCore(final SystemResources resources, Random random, int clientType, final byte[] clientName, ClientConfigP config, String applicationName, RunStateP ticlRunState, RegistrationManagerStateP regManagerState, ProtocolHandlerState protocolHandlerState, StatisticsState statisticsState, InvalidationListener listener) { this.resources = Preconditions.checkNotNull(resources); this.random = random; this.logger = Preconditions.checkNotNull(resources.getLogger()); this.internalScheduler = resources.getInternalScheduler(); this.storage = resources.getStorage(); this.config = config; this.ticlState = (ticlRunState == null) ? new RunState() : new RunState(ticlRunState); this.smearer = new Smearer(random, this.config.getSmearPercent()); this.applicationClientId = CommonProtos2.newApplicationClientIdP(clientType, ByteString.copyFrom(clientName)); this.listener = listener; this.msgValidator = new TiclMessageValidator2(resources.getLogger()); this.statistics = (statisticsState != null) ? Statistics.deserializeStatistics(resources.getLogger(), statisticsState.getCounterList()) : new Statistics(); this.registrationManager = new RegistrationManager(logger, statistics, digestFn, regManagerState); this.protocolHandler = new ProtocolHandler(config.getProtocolHandlerConfig(), resources, smearer, statistics, clientType, applicationName, this, msgValidator, protocolHandlerState); }
Example #23
Source File: AndroidInvalidationListenerStub.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@SuppressWarnings("unchecked") private Class<? extends InvalidationListener> getListenerClass() { try { // Find the listener class that the application wants to use to receive upcalls. return (Class<? extends InvalidationListener>) Class.forName(new AndroidTiclManifest(this).getListenerClass()); } catch (ClassNotFoundException exception) { throw new RuntimeException("Invalid listener class", exception); } }
Example #24
Source File: InvalidationTestListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void informError(InvalidationClient client, ErrorInfo errorInfo) { InvalidationListener listener = getListener(client); logger.fine("Received INFORM_ERROR for %s: %s", getClientKey(client), listener); if (listener != null) { listener.informError(client, errorInfo); } }
Example #25
Source File: InvalidationTestListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void reissueRegistrations(InvalidationClient client, byte[] prefix, int prefixLength) { InvalidationListener listener = getListener(client); logger.fine("Received REISSUE_REGISTRATIONS for %s: %s", getClientKey(client), listener); if (listener != null) { listener.reissueRegistrations(client, prefix, prefixLength); } }
Example #26
Source File: InvalidationTestListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void informRegistrationFailure( InvalidationClient client, ObjectId objectId, boolean isTransient, String errorMessage) { InvalidationListener listener = getListener(client); logger.fine("Received INFORM_REGISTRATION_FAILURE for %s: %s", getClientKey(client), listener); if (listener != null) { listener.informRegistrationFailure(client, objectId, isTransient, errorMessage); } }
Example #27
Source File: InvalidationTestListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void informRegistrationStatus( InvalidationClient client, ObjectId objectId, RegistrationState regState) { InvalidationListener listener = getListener(client); logger.fine("Received INFORM_REGISTRATION_STATUS for %s: %s", getClientKey(client), listener); if (listener != null) { listener.informRegistrationStatus(client, objectId, regState); } }
Example #28
Source File: InvalidationTestListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void invalidateAll(InvalidationClient client, AckHandle ackHandle) { InvalidationListener listener = getListener(client); logger.fine("Received INVALIDATE_ALL for %s: %s", getClientKey(client), listener); if (listener != null) { listener.invalidateAll(client, ackHandle); } }
Example #29
Source File: InvalidationTestListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void invalidateUnknownVersion( InvalidationClient client, ObjectId objectId, AckHandle ackHandle) { InvalidationListener listener = getListener(client); logger.fine("Received INVALIDATE_UNKNOWN_VERSION for %s: %s", getClientKey(client), listener); if (listener != null) { listener.invalidateUnknownVersion(client, objectId, ackHandle); } }
Example #30
Source File: InvalidationTestListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void invalidate( InvalidationClient client, Invalidation invalidation, AckHandle ackHandle) { InvalidationListener listener = getListener(client); logger.fine("Received INVALIDATE for %s: %s", getClientKey(client), listener); if (listener != null) { listener.invalidate(client, invalidation, ackHandle); } }