This repository has been archived by the owner on Sep 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manage lifecycle of installed modules (#357)
* Manage lifecycle of installed modules When an ApolloModule installs another ApolloModule, it should start managing lifecycles for all the keys from the installed ApolloModule. Apollo will not manage the installed modules on the service shutdown if we don't do this.
- Loading branch information
Showing
4 changed files
with
120 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
apollo-core/src/test/java/com/spotify/apollo/core/ChildModuleWithLifecycledKeys.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* -\-\- | ||
* Spotify Apollo Service Core (aka Leto) | ||
* -- | ||
* Copyright (C) 2013 - 2020 Spotify AB | ||
* -- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* -/-/- | ||
*/ | ||
package com.spotify.apollo.core; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.name.Named; | ||
import com.google.inject.name.Names; | ||
import com.spotify.apollo.module.AbstractApolloModule; | ||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
class ChildModuleWithLifecycledKeys extends AbstractApolloModule { | ||
|
||
private final AtomicBoolean created; | ||
private final AtomicBoolean closed; | ||
|
||
public ChildModuleWithLifecycledKeys(AtomicBoolean created, AtomicBoolean closed) { | ||
this.created = created; | ||
this.closed = closed; | ||
} | ||
|
||
@Override | ||
protected void configure() { | ||
bind(AtomicBoolean.class).annotatedWith(Names.named("childCreated")).toInstance(created); | ||
bind(AtomicBoolean.class).annotatedWith(Names.named("childClosed")).toInstance(closed); | ||
|
||
bind(Foo.class).to(FooImpl.class); | ||
manageLifecycle(Foo.class); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return "child-lifecycle-module"; | ||
} | ||
|
||
interface Foo {} | ||
|
||
static class FooImpl implements Foo, Closeable { | ||
|
||
final AtomicBoolean closed; | ||
|
||
@Inject | ||
FooImpl( | ||
@Named("childCreated") AtomicBoolean created, @Named("childClosed") AtomicBoolean closed) { | ||
this.closed = closed; | ||
created.set(true); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
closed.set(true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters