-
Notifications
You must be signed in to change notification settings - Fork 581
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add InstantiatorService to abstract user instance creation
- Loading branch information
1 parent
51ae2e4
commit 9d9fc1a
Showing
33 changed files
with
742 additions
and
602 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
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
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
23 changes: 23 additions & 0 deletions
23
ehcache-core/src/main/java/org/ehcache/core/spi/service/InstantiatorService.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,23 @@ | ||
/* | ||
* Copyright Terracotta, Inc. | ||
* | ||
* 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 org.ehcache.core.spi.service; | ||
|
||
import org.ehcache.spi.service.Service; | ||
|
||
public interface InstantiatorService extends Service { | ||
|
||
<T> T instantiate(Class<T> clazz, Object ... arguments) throws IllegalArgumentException; | ||
} |
44 changes: 44 additions & 0 deletions
44
ehcache-core/src/testFixtures/java/org/ehcache/core/spi/ServiceLocatorUtils.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,44 @@ | ||
/* | ||
* Copyright Terracotta, Inc. | ||
* | ||
* 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 org.ehcache.core.spi; | ||
|
||
import org.ehcache.spi.service.Service; | ||
|
||
import java.util.function.UnaryOperator; | ||
|
||
public interface ServiceLocatorUtils { | ||
|
||
static <T extends Service> void withServiceLocator(T service, ServiceTask<T> task) throws Exception { | ||
withServiceLocator(service, UnaryOperator.identity(), task); | ||
} | ||
|
||
static <T extends Service> void withServiceLocator(T service, UnaryOperator<ServiceLocator.DependencySet> dependencies, ServiceTask<T> task) throws Exception { | ||
ServiceLocator serviceLocator = dependencies.apply(ServiceLocator.dependencySet().with(service)).build(); | ||
serviceLocator.startAllServices(); | ||
try { | ||
task.execute(service); | ||
} finally { | ||
serviceLocator.stopAllServices(); | ||
} | ||
} | ||
|
||
@FunctionalInterface | ||
interface ServiceTask<T extends Service> { | ||
|
||
void execute(T service) throws Exception; | ||
} | ||
|
||
} |
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
Oops, something went wrong.