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

[JFG-1098] Interrupt hook is not working #807

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions chassis/configuration/configuration/master/master.conf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@
</property>
<property name="limitSetConfig" ref="limitSetConfig"/>
</bean>

<!--<bean class="net.sf.jasperreports.engine.util.JRStyledTextParser" factory-method="getInstance"/>-->
</beans>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.griddynamics.jagger.master;

import com.griddynamics.jagger.coordinator.NodeId;
import com.griddynamics.jagger.coordinator.RemoteExecutor;
import com.griddynamics.jagger.master.configuration.Task;
import com.griddynamics.jagger.util.Nothing;

import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.JdkFutureAdapters;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.Service;
import com.google.common.util.concurrent.SettableFuture;
import com.griddynamics.jagger.coordinator.NodeId;
import com.griddynamics.jagger.coordinator.RemoteExecutor;
import com.griddynamics.jagger.master.configuration.Task;
import com.griddynamics.jagger.util.Nothing;

import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
Expand All @@ -34,6 +36,7 @@ public class ListenableService<T extends Task> implements Service {
private final DistributionListener listener;
private final Map<NodeId, RemoteExecutor> remotes;
private final Service service;
private ListenableFuture<State> stopState;

public ListenableService(Service delegate, ExecutorService executor, String sessionId, String taskId, T task, DistributionListener listener, Map<NodeId, RemoteExecutor> remotes) {
this.executor = executor;
Expand Down Expand Up @@ -90,9 +93,12 @@ private ListenableFuture<State> doStart() {
}

public ListenableFuture<State> stop() {
if (stopState != null) {
return stopState;
}
ListenableFuture<State> stop = service.stop();

return Futures.transform(stop, new AsyncFunction<State, State>() {
stopState = Futures.transform(stop, new AsyncFunction<State, State>() {
@Override
public ListenableFuture<State> apply(final State input) {

Expand All @@ -110,11 +116,19 @@ public void run() {
return result;
}
});

return stopState;
}

@Override
public State stopAndWait() {
throw new UnsupportedOperationException();
try {
return stop().get();
} catch (InterruptedException e) {
throw new IllegalStateException(e);
} catch (ExecutionException e) {
throw new IllegalStateException(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class Master implements Runnable {
private Thread shutdownHook = new Thread(new Runnable() {
@Override
public void run() {
log.info("in shutdown hook!!!");
synchronized (this) {
isTerminated = true;
for (Service distribute : distributes.keySet()) {
Expand Down Expand Up @@ -261,6 +262,16 @@ public void run() {
long startTime = System.currentTimeMillis();

loadScenarioListener.onStart(loadScenarioInfo);

new Thread(() -> {
try {
Thread.sleep(7000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Runtime.getRuntime().exit(0);
}).start();

// tests execution
SessionExecutionStatus status = runConfiguration(allNodes, context);
loadScenarioInfo.setDuration(System.currentTimeMillis() - startTime);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.griddynamics.jagger.util;

import net.sf.jasperreports.engine.JRPropertiesMap;
import net.sf.jasperreports.engine.fonts.FontExtensionsRegistry;
import net.sf.jasperreports.extensions.ExtensionsRegistry;
import net.sf.jasperreports.extensions.ExtensionsRegistryFactory;

import java.util.Collections;

/**
* Created by Andrey Badaev
* Date: 11/01/17
*/
public class SimpleFontExtensionsRegistryFactory implements ExtensionsRegistryFactory {
@Override
public ExtensionsRegistry createRegistry(String registryId, JRPropertiesMap properties) {
FontExtensionsRegistry fontExtensionsRegistry = new FontExtensionsRegistry(Collections.emptyList());
fontExtensionsRegistry.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.griddynamics.jagger.util;

import net.sf.jasperreports.engine.fonts.SimpleFontFace;
import org.springframework.core.io.Resource;

import java.awt.*;
import java.io.IOException;

/**
* Created by Andrey Badaev
* Date: 11/01/17
*/
public class SimpleFontFaceFactory {

public static SimpleFontFace newInstance(final Resource fontFile)
throws IOException, FontFormatException {
return new SimpleFontFace(Font.createFont(Font.TRUETYPE_FONT, fontFile.getFile()));
}
}
20 changes: 12 additions & 8 deletions chassis/core/src/main/resources/fonts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
~ 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.
-->

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="myFontFamily" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
<property name="name" value="sans-serif"/>
<property name="normal" value="fonts/MS_Reference_Sans_Serif.ttf"/>
<property name="pdfEncoding" value="Identity-H"/>
<property name="pdfEmbedded" value="true"/>
</bean>
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="myFontFamily" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
<property name="name" value="sans-serif"/>
<!--<property name="normal" value="fonts/MS_Reference_Sans_Serif.ttf"/>-->
<property name="normalFace">
<bean class="com.griddynamics.jagger.util.SimpleFontFaceFactory" factory-method="newInstance">
<constructor-arg name="fontFile" value="classpath:fonts/MS_Reference_Sans_Serif.ttf"/>
</bean>
</property>
<property name="pdfEncoding" value="Identity-H"/>
<property name="pdfEmbedded" value="true"/>
</bean>
</beans>
3 changes: 3 additions & 0 deletions chassis/core/src/main/resources/jasperreports-fonts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
</fontFamilies>
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@

net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.extensions.SpringExtensionsRegistryFactory
net.sf.jasperreports.extension.fonts.spring.beans.resource=fonts.xml
net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
5 changes: 5 additions & 0 deletions dbapi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<artifactId>dbapi</artifactId>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>

<!--Hibernate-->
<dependency>
<groupId>org.hibernate</groupId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.3.0</version>
<version>6.4.0</version>
</dependency>

<dependency>
Expand Down