@Test public void getInstanceRoot() { final ChannelSchema channelSchema = new ChannelSchema( 0, ValueUtil.randomString(), A.class, ChannelSchema.FilterType.NONE, null, false, true, Collections.emptyList() ); createConnector( new SystemSchema( 1, ValueUtil.randomString(), new ChannelSchema[]{ channelSchema }, new EntitySchema[ 0 ] ) ); final ChannelAddress address1 = new ChannelAddress( 1, 0, 33 ); final Subscription subscription1 = Subscription.create( null, address1, null, true ); final EntityService entityService = Replicant.context().getEntityService(); final Entity entity1 = safeAction( () -> entityService.findOrCreateEntity( "A/33", A.class, 33 ) ); final A entity = new A(); safeAction( () -> entity1.setUserObject( entity ) ); safeAction( () -> subscription1.linkSubscriptionToEntity( entity1 ) ); safeAction( () -> assertEquals( subscription1.getInstanceRoot(), entity ) ); }
@Nonnull public Object getInstanceRoot() { final ChannelSchema channel = getChannelSchema(); final Integer id = _address.getId(); if ( Replicant.shouldCheckApiInvariants() ) { invariant( channel::isInstanceChannel, () -> "Replicant-0029: Subscription.getInstanceRoot() invoked on subscription for channel " + _address + " but channel is not instance based." ); invariant( () -> null != id, () -> "Replicant-0087: Subscription.getInstanceRoot() invoked on subscription for channel " + _address + " but channel has not supplied expected id." ); } assert null != id; final Entity entity = findEntityByTypeAndId( Objects.requireNonNull( channel.getInstanceType() ), id ); if ( Replicant.shouldCheckApiInvariants() ) { invariant( () -> null != entity, () -> "Replicant-0088: Subscription.getInstanceRoot() invoked on subscription for channel " + _address + " but entity is not present." ); } assert null != entity; return entity.getUserObject(); }
Subscription extends ReplicantService implements Comparable<Subscription> { @Nonnull public Object getInstanceRoot() { final ChannelSchema channel = getChannelSchema(); final Integer id = _address.getId(); if ( Replicant.shouldCheckApiInvariants() ) { invariant( channel::isInstanceChannel, () -> "Replicant-0029: Subscription.getInstanceRoot() invoked on subscription for channel " + _address + " but channel is not instance based." ); invariant( () -> null != id, () -> "Replicant-0087: Subscription.getInstanceRoot() invoked on subscription for channel " + _address + " but channel has not supplied expected id." ); } assert null != id; final Entity entity = findEntityByTypeAndId( Objects.requireNonNull( channel.getInstanceType() ), id ); if ( Replicant.shouldCheckApiInvariants() ) { invariant( () -> null != entity, () -> "Replicant-0088: Subscription.getInstanceRoot() invoked on subscription for channel " + _address + " but entity is not present." ); } assert null != entity; return entity.getUserObject(); } }
Subscription extends ReplicantService implements Comparable<Subscription> { @Nonnull public Object getInstanceRoot() { final ChannelSchema channel = getChannelSchema(); final Integer id = _address.getId(); if ( Replicant.shouldCheckApiInvariants() ) { invariant( channel::isInstanceChannel, () -> "Replicant-0029: Subscription.getInstanceRoot() invoked on subscription for channel " + _address + " but channel is not instance based." ); invariant( () -> null != id, () -> "Replicant-0087: Subscription.getInstanceRoot() invoked on subscription for channel " + _address + " but channel has not supplied expected id." ); } assert null != id; final Entity entity = findEntityByTypeAndId( Objects.requireNonNull( channel.getInstanceType() ), id ); if ( Replicant.shouldCheckApiInvariants() ) { invariant( () -> null != entity, () -> "Replicant-0088: Subscription.getInstanceRoot() invoked on subscription for channel " + _address + " but entity is not present." ); } assert null != entity; return entity.getUserObject(); } Subscription( @Nullable final ReplicantContext context, @Nonnull final ChannelAddress address ); }
Subscription extends ReplicantService implements Comparable<Subscription> { @Nonnull public Object getInstanceRoot() { final ChannelSchema channel = getChannelSchema(); final Integer id = _address.getId(); if ( Replicant.shouldCheckApiInvariants() ) { invariant( channel::isInstanceChannel, () -> "Replicant-0029: Subscription.getInstanceRoot() invoked on subscription for channel " + _address + " but channel is not instance based." ); invariant( () -> null != id, () -> "Replicant-0087: Subscription.getInstanceRoot() invoked on subscription for channel " + _address + " but channel has not supplied expected id." ); } assert null != id; final Entity entity = findEntityByTypeAndId( Objects.requireNonNull( channel.getInstanceType() ), id ); if ( Replicant.shouldCheckApiInvariants() ) { invariant( () -> null != entity, () -> "Replicant-0088: Subscription.getInstanceRoot() invoked on subscription for channel " + _address + " but entity is not present." ); } assert null != entity; return entity.getUserObject(); } Subscription( @Nullable final ReplicantContext context, @Nonnull final ChannelAddress address ); @Nonnull ChannelAddress getAddress(); @Observable( initializer = Feature.ENABLE ) @Nullable abstract Object getFilter(); @Observable( initializer = Feature.ENABLE ) abstract boolean isExplicitSubscription(); abstract void setExplicitSubscription( boolean explicitSubscription ); @Nonnull Collection<Class<?>> findAllEntityTypes(); @Nonnull List<Entity> findAllEntitiesByType( @Nonnull final Class<?> type ); @Nullable Entity findEntityByTypeAndId( @Nonnull final Class<?> type, final int id ); @Nonnull Object getInstanceRoot(); @Nonnull ChannelSchema getChannelSchema(); @Override int compareTo( @Nonnull final Subscription o ); }
Subscription extends ReplicantService implements Comparable<Subscription> { @Nonnull public Object getInstanceRoot() { final ChannelSchema channel = getChannelSchema(); final Integer id = _address.getId(); if ( Replicant.shouldCheckApiInvariants() ) { invariant( channel::isInstanceChannel, () -> "Replicant-0029: Subscription.getInstanceRoot() invoked on subscription for channel " + _address + " but channel is not instance based." ); invariant( () -> null != id, () -> "Replicant-0087: Subscription.getInstanceRoot() invoked on subscription for channel " + _address + " but channel has not supplied expected id." ); } assert null != id; final Entity entity = findEntityByTypeAndId( Objects.requireNonNull( channel.getInstanceType() ), id ); if ( Replicant.shouldCheckApiInvariants() ) { invariant( () -> null != entity, () -> "Replicant-0088: Subscription.getInstanceRoot() invoked on subscription for channel " + _address + " but entity is not present." ); } assert null != entity; return entity.getUserObject(); } Subscription( @Nullable final ReplicantContext context, @Nonnull final ChannelAddress address ); @Nonnull ChannelAddress getAddress(); @Observable( initializer = Feature.ENABLE ) @Nullable abstract Object getFilter(); @Observable( initializer = Feature.ENABLE ) abstract boolean isExplicitSubscription(); abstract void setExplicitSubscription( boolean explicitSubscription ); @Nonnull Collection<Class<?>> findAllEntityTypes(); @Nonnull List<Entity> findAllEntitiesByType( @Nonnull final Class<?> type ); @Nullable Entity findEntityByTypeAndId( @Nonnull final Class<?> type, final int id ); @Nonnull Object getInstanceRoot(); @Nonnull ChannelSchema getChannelSchema(); @Override int compareTo( @Nonnull final Subscription o );  }