Skip to content

Commit f4ad469

Browse files
committed
MERGE PREP: Introduced base interface "Resource" to allow basic lookup API to be consolidated in ResourceSet.
Approach copied from "master".
1 parent 7b2ee78 commit f4ad469

12 files changed

+134
-31
lines changed

src/main/java/crud/core/ReadableResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
* @author Rick Warren
3131
*/
32-
public interface ReadableResource<E> extends AsyncCloseable {
32+
public interface ReadableResource<E> extends Resource {
3333

3434
/**
3535
* Begin observation of the data elements. The {@link Observable} may be

src/main/java/crud/core/ReadableResourceSet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public interface ReadableResourceSet<K, E> extends ResourceSet<K, E> {
3939
* obtained from a {@link DataBus} compatible with this
4040
* {@link ReadableResourceSet}.
4141
*/
42+
@Override
4243
public @Nonnull ReadableResource<E> resource(@Nonnull K key, @Nonnull Session session);
4344

4445

src/main/java/crud/core/Resource.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* Copyright 2015 Rick Warren
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
4+
* use this file except in compliance with the License. You may obtain a copy of
5+
* the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and limitations under
13+
* the License.
14+
*/
15+
package crud.core;
16+
17+
18+
/**
19+
* An abstract stateful entity, whose value may be retrieved via the
20+
* sub-interface {@link ReadableResource}, or modified via the sub-interface
21+
* {@link WritableResource}.
22+
*
23+
* @author Rick Warren
24+
*/
25+
public interface Resource extends AsyncCloseable {
26+
// empty
27+
}

src/main/java/crud/core/ResourceSet.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ public interface ResourceSet<K, E> {
3838
*/
3939
public @Nonnull Id<K, E> getId();
4040

41+
/**
42+
* Return a {@link Resource} identified by the given key, to be accessed
43+
* in the context of the given {@link Session}.
44+
*
45+
* @throws ClassCastException If the {@link Session} was not
46+
* obtained from a {@link DataBus} compatible with this
47+
* {@link WritableResourceSet}.
48+
*/
49+
public @Nonnull Resource resource(@Nonnull K key, @Nonnull Session session);
50+
4151

4252
/**
4353
* Identifies a {@link ResourceSet}: a named collection of homogeneously-typed

src/main/java/crud/core/WritableResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
* @author Rick Warren
3131
*/
32-
public interface WritableResource<E, R> extends AsyncCloseable {
32+
public interface WritableResource<E, R> extends Resource {
3333

3434
/**
3535
* Write a single data element to the target middleware. Return to the

src/main/java/crud/core/WritableResourceSet.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ public interface WritableResourceSet<K, E, R> extends ResourceSet<K, E> {
4040
* @throws ClassCastException If the {@link Session} was not
4141
* obtained from a {@link DataBus} compatible with this
4242
* {@link WritableResourceSet}.
43-
* @throws UnsupportedOperationException If this {@link WritableResourceSet} cannot
44-
* be written.
4543
*/
44+
@Override
4645
public @Nonnull WritableResource<E, R> resource(@Nonnull K key, @Nonnull Session session);
4746

4847

src/main/java/crud/sync/SyncReadableResource.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
import javax.annotation.Nonnull;
1818

1919
import crud.core.ReadableResource;
20-
import crud.implementer.AsyncResults;
2120

2221

2322
/**
2423
* @see ReadableResource
2524
*
2625
* @author Rick Warren
2726
*/
28-
public class SyncReadableResource<E> extends SyncDelegateHolder<ReadableResource<E>> implements AutoCloseable {
27+
public class SyncReadableResource<E> extends SyncResource<ReadableResource<E>> {
2928

3029
public SyncReadableResource(@Nonnull final ReadableResource<E> delegate) {
3130
super(delegate);
@@ -38,12 +37,4 @@ public Iterable<E> read() {
3837
return getDelegate().read().toBlocking().toIterable();
3938
}
4039

41-
/**
42-
* @see ReadableResource#shutdown()
43-
*/
44-
@Override
45-
public void close() throws Exception {
46-
AsyncResults.awaitShutdown(getDelegate());
47-
}
48-
4940
}

src/main/java/crud/sync/SyncReadableResourceSet.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import crud.core.ReadableResource;
2020
import crud.core.ReadableResourceSet;
21-
import crud.core.ReadableResourceSet.Id;
2221
import crud.core.Session;
2322

2423

@@ -27,7 +26,7 @@
2726
*
2827
* @author Rick Warren
2928
*/
30-
public class SyncReadableResourceSet<K, E> extends SyncDelegateHolder<ReadableResourceSet<K, E>> {
29+
public class SyncReadableResourceSet<K, E> extends SyncResourceSet<K, E, ReadableResourceSet<K, E>> {
3130

3231
public SyncReadableResourceSet(@Nonnull final ReadableResourceSet<K, E> delegate) {
3332
super(delegate);
@@ -36,13 +35,15 @@ public SyncReadableResourceSet(@Nonnull final ReadableResourceSet<K, E> delegate
3635
/**
3736
* @see ReadableResourceSet#getId()
3837
*/
39-
public @Nonnull Id<K, E> getId() {
38+
@Override
39+
public @Nonnull ReadableResourceSet.Id<K, E> getId() {
4040
return getDelegate().getId();
4141
}
4242

4343
/**
4444
* @see ReadableResourceSet#resource(Object, Session)
4545
*/
46+
@Override
4647
public @Nonnull SyncReadableResource<E> resource(@Nonnull final K key, @Nonnull final SyncSession session) {
4748
final ReadableResource<E> delegateSource = getDelegate().resource(key, session.getDelegate());
4849
return new SyncReadableResource<>(delegateSource);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* Copyright 2015 Rick Warren
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
4+
* use this file except in compliance with the License. You may obtain a copy of
5+
* the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and limitations under
13+
* the License.
14+
*/
15+
package crud.sync;
16+
17+
import crud.core.Resource;
18+
import crud.implementer.AsyncResults;
19+
20+
21+
public abstract class SyncResource<D extends Resource>
22+
extends SyncDelegateHolder<D>
23+
implements AutoCloseable {
24+
25+
/**
26+
* @see Resource#shutdown()
27+
*/
28+
@Override
29+
public final void close() throws Exception {
30+
AsyncResults.awaitShutdown(getDelegate());
31+
}
32+
33+
/*package*/ SyncResource(final D delegate) {
34+
super(delegate);
35+
}
36+
37+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* Copyright 2015 Rick Warren
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
4+
* use this file except in compliance with the License. You may obtain a copy of
5+
* the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and limitations under
13+
* the License.
14+
*/
15+
package crud.sync;
16+
17+
import javax.annotation.Nonnull;
18+
19+
import crud.core.ResourceSet;
20+
import crud.core.Session;
21+
22+
23+
/**
24+
* @see ResourceSet
25+
*/
26+
public abstract class SyncResourceSet<K, E, D extends ResourceSet<K, E>>
27+
extends SyncDelegateHolder<D> {
28+
29+
/**
30+
* @see ResourceSet#getId()
31+
*/
32+
public abstract @Nonnull ResourceSet.Id<K, E> getId();
33+
34+
/**
35+
* @see ResourceSet#resource(Object, Session)
36+
*/
37+
public abstract @Nonnull SyncResource<?> resource(
38+
@Nonnull final K key,
39+
@Nonnull final SyncSession session);
40+
41+
/*package*/ SyncResourceSet(final D delegate) {
42+
super(delegate);
43+
}
44+
45+
}

0 commit comments

Comments
 (0)