-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Three things to improve startup time:
Don't load Bouncy Castle until the "crypto" module is required, not when the Java code is first loaded. Pre-compile scripts in the "util" module rather than compiling them on every startup. Use "slf4j-simple" in the pre-built JAR rather than logback.
- Loading branch information
Gregory Brail
committed
Jun 18, 2015
1 parent
9705116
commit 49fdadb
Showing
13 changed files
with
194 additions
and
38 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
41 changes: 41 additions & 0 deletions
41
core/src/main/java/io/apigee/trireme/core/NodePrecompiledModule.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,41 @@ | ||
/** | ||
* Copyright 2015 Apigee Corporation. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package io.apigee.trireme.core; | ||
|
||
/** | ||
* This interface is used to write new modules in JavaScript that are plugged in to Noderunner as built-in | ||
* modules. Implementators must register their modules using the java.util.ServiceLoader pattern, | ||
* by creating a file in their JAR called "META-INF/services/io.apigee.trireme.core.NodePrecompiledModule" | ||
* and listing, one per line, the name of their implementation classes. The "rhino-compiler" module | ||
* from Trireme is a great way to do this. | ||
*/ | ||
public interface NodePrecompiledModule | ||
{ | ||
/** | ||
* Return a two-dimensional array of strings denoting the script sources. Each element must be a two-element | ||
* array. The first element must be the name of the module, and the second must be the name of a | ||
* class that represents a compiled Rhino script (an instance of Rhino's Script class). | ||
* The loader will use the implementation class's classloader | ||
* to get the compiled script. | ||
*/ | ||
String[][] getCompiledScripts(); | ||
} |
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
71 changes: 71 additions & 0 deletions
71
core/src/main/java/io/apigee/trireme/core/modules/crypto/CryptoLoader.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,71 @@ | ||
/** | ||
* Copyright 2015 Apigee Corporation. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package io.apigee.trireme.core.modules.crypto; | ||
|
||
import io.apigee.trireme.kernel.crypto.CryptoService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.security.Provider; | ||
import java.util.ServiceLoader; | ||
|
||
/** | ||
* This is a singleton class to ensure that we only load the BouncyCastle crypto provider once | ||
* per JVM, but for startup time reasons we don't load it until we actually require the "crypto" | ||
* module once. | ||
*/ | ||
|
||
public class CryptoLoader | ||
{ | ||
private static final Logger log = LoggerFactory.getLogger(CryptoLoader.class.getName()); | ||
|
||
private CryptoService cryptoService; | ||
private Provider cryptoProvider; | ||
|
||
private static final CryptoLoader myself = new CryptoLoader(); | ||
|
||
private CryptoLoader() | ||
{ | ||
ServiceLoader<CryptoService> loc = ServiceLoader.load(CryptoService.class); | ||
if (loc.iterator().hasNext()) { | ||
if (log.isDebugEnabled()) { | ||
log.debug("Using crypto service implementation {}", cryptoService); | ||
} | ||
cryptoService = loc.iterator().next(); | ||
cryptoProvider = cryptoService.getProvider(); | ||
} else if (log.isDebugEnabled()) { | ||
log.debug("No crypto service available"); | ||
} | ||
} | ||
|
||
public static CryptoLoader get() { | ||
return myself; | ||
} | ||
|
||
public CryptoService getCryptoService() { | ||
return cryptoService; | ||
} | ||
|
||
public Provider getCryptoProvider() { | ||
return cryptoProvider; | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.