Skip to content

Commit

Permalink
Merge pull request #17 from TIHBS/start-plguins-option-on-start
Browse files Browse the repository at this point in the history
Optional boolean flag to enable plugins at start
  • Loading branch information
akshay-ap authored Apr 27, 2022
2 parents c7cf9d0 + 96a09a6 commit eca5e63
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ mvn install
Then, the WAR file (which can be found in the folder 'target' generated after a successful build) can be deployed on an
Apache Tomcat server.

Required VM options while running
VM options while running

- `pf4j.pluginsDir` path where the plugins will be stored
- `pf4j.pluginsDir` path where the plugins will be stored. This property is mandatory.
- `enablePluginsAtStart` boolean flag to enable plugins during startup (default false). This property is optional.

## Plugin management

Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,25 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import org.pf4j.*;
import org.pf4j.DefaultPluginManager;
import org.pf4j.PluginManager;
import org.pf4j.PluginState;
import org.pf4j.PluginWrapper;
import org.pf4j.ManifestPluginDescriptorFinder;
import org.pf4j.DependencyResolver.DependenciesNotFoundException;
import org.pf4j.JarPluginLoader;
import org.pf4j.PluginDescriptorFinder;
import org.pf4j.PluginLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Path;
import java.util.List;

public class BlockchainPluginManager {

private static final Logger log = LoggerFactory.getLogger(BlockchainPluginManager.class);

private PluginManager pluginManager = null;
private static BlockchainPluginManager instance = null;

Expand All @@ -41,8 +53,12 @@ protected PluginDescriptorFinder createPluginDescriptorFinder() {
return new ManifestPluginDescriptorFinder();
}
};

pluginManager.loadPlugins();

if (Boolean.getBoolean("enablePluginsAtStart")) {
pluginManager.startPlugins();
}
}

public static BlockchainPluginManager getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.pf4j.DependencyResolver.DependenciesNotFoundException;
import org.pf4j.PluginWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -47,10 +48,12 @@ public Response uploadJar(@FormDataParam("file") InputStream uploadedInputStream
return Response.status(Response.Status.BAD_REQUEST).entity("File already exists with same name.").build();
}
writeToFile(uploadedInputStream, uploadedFileLocation);

blockchainPluginManager.loadJar(filePath);

return Response.ok().build();
try {
blockchainPluginManager.loadJar(filePath);
return Response.ok().build();
} catch (DependenciesNotFoundException e) {
return Response.status(400).entity(e.getMessage()).type("text/plain").build();
}
}

@POST
Expand Down

0 comments on commit eca5e63

Please sign in to comment.