Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #3471 - Add CRaCFeature #3476

Merged
merged 4 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@
*/
package cloud.piranha.feature.api;

import java.util.List;

/**
* The Feature Manager API.
*
* @author Manfred Riem ([email protected])
*/
public interface FeatureManager {

/**
* Get the features.
*
* @return the features.
*/
List<Feature> getFeatures();
}
32 changes: 32 additions & 0 deletions feature/crac/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cloud.piranha.feature</groupId>
<artifactId>project</artifactId>
<version>23.7.0-SNAPSHOT</version>
</parent>
<artifactId>piranha-feature-crac</artifactId>
<packaging>jar</packaging>
<name>Piranha - Feature - CRaC</name>
<dependencies>
<dependency>
<groupId>cloud.piranha.feature</groupId>
<artifactId>piranha-feature-http</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cloud.piranha.feature</groupId>
<artifactId>piranha-feature-https</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cloud.piranha.http</groupId>
<artifactId>piranha-http-crac</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
101 changes: 101 additions & 0 deletions feature/crac/src/main/java/cloud/piranha/feature/crac/CracFeature.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.feature.crac;

import cloud.piranha.feature.api.Feature;
import cloud.piranha.feature.api.FeatureManager;
import cloud.piranha.feature.http.HttpFeature;
import cloud.piranha.feature.https.HttpsFeature;
import cloud.piranha.http.api.HttpServer;
import java.lang.System.Logger;
import static java.lang.System.Logger.Level.ERROR;
import java.lang.reflect.InvocationTargetException;

/**
* The CRaC feature that enables Project CRaC.
*
* @author Manfred Riem ([email protected])
*/
public class CracFeature implements Feature {

/**
* Stores the logger.
*/
private static final Logger LOGGER = System.getLogger(CracFeature.class.getName());

/**
* Stores the feature manager.
*/
private FeatureManager featureManager;

/**
* Create the CRaC HttpServer instance.
*
* @param httpServer the HttpServer instance to wrap.
* @return the CRaC HttpServer instance.
*/
private HttpServer createCracHttpServer(HttpServer httpServer) {
HttpServer cracHttpServer = null;
try {
cracHttpServer = (HttpServer) Class
.forName("cloud.piranha.http.crac.CracHttpServer")
.getDeclaredConstructor(HttpServer.class)
.newInstance(httpServer);
} catch (ClassNotFoundException | IllegalAccessException
| IllegalArgumentException | InstantiationException
| NoSuchMethodException | SecurityException
| InvocationTargetException t) {
LOGGER.log(ERROR, "Unable to construct CracHttpServer", t);
}
return cracHttpServer;
}

@Override
public FeatureManager getFeatureManager() {
return featureManager;
}

@Override
public void setFeatureManager(FeatureManager featureManager) {
this.featureManager = featureManager;
}

@Override
public void init() {
for (Feature feature : featureManager.getFeatures()) {
if (feature instanceof HttpFeature httpFeature) {
HttpServer cracHttpServer = createCracHttpServer(httpFeature.getHttpServer());
httpFeature.setHttpServer(cracHttpServer);
}
if (feature instanceof HttpsFeature httpsFeature) {
HttpServer cracHttpServer = createCracHttpServer(httpsFeature.getHttpsServer());
httpsFeature.setHttpsServer(cracHttpServer);
}
}
}
}
43 changes: 43 additions & 0 deletions feature/crac/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2002-2023 Manorrock.com. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

/**
* This module delivers the CRaC Feature.
*
* @author Manfred Riem ([email protected])
*/
module cloud.piranha.feature.crac {

exports cloud.piranha.feature.crac;
opens cloud.piranha.feature.crac;
requires cloud.piranha.feature.api;
requires static cloud.piranha.feature.http;
requires static cloud.piranha.feature.https;
requires cloud.piranha.http.api;
requires cloud.piranha.http.crac;
}
1 change: 1 addition & 0 deletions feature/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<modules>
<module>api</module>
<module>crac</module>
<module>http</module>
<module>https</module>
</modules>
Expand Down