Skip to content

Commit

Permalink
use STA when COM timeout is disabled, otherwise MTA
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoenisch committed Feb 12, 2018
1 parent 027372a commit ed1f244
Show file tree
Hide file tree
Showing 15 changed files with 235 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2017 TraceTronic GmbH
* Copyright (c) 2015-2018 TraceTronic GmbH
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -335,8 +335,9 @@ protected ETInstallation configureToolInstallation(final String toolName, final
} else {
throw new ETPluginException("The selected ECU-TEST installation is not configured for this node!");
}
// Set the COM programmatic identifier for the current ECU-TEST instance
// Set the COM settings for the current ECU-TEST instance
ETComProperty.getInstance().setProgId(installation.getProgId());
ETComProperty.getInstance().setTimeout(installation.getTimeout());
return installation;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2017 TraceTronic GmbH
* Copyright (c) 2015-2018 TraceTronic GmbH
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -193,8 +193,9 @@ protected ETInstallation configureToolInstallation(final Computer computer, fina
} else {
throw new ETPluginException("The selected ECU-TEST installation is not configured for this node!");
}
// Set the COM programmatic identifier for the current ECU-TEST instance
// Set the COM settings for the current ECU-TEST instance
ETComProperty.getInstance().setProgId(installation.getProgId());
ETComProperty.getInstance().setTimeout(installation.getTimeout());
return installation;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2017 TraceTronic GmbH
* Copyright (c) 2015-2018 TraceTronic GmbH
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -38,8 +38,8 @@
import hudson.XmlFile;
import hudson.model.TaskListener;
import hudson.model.Node;
import hudson.tools.ToolProperty;
import hudson.tools.ToolDescriptor;
import hudson.tools.ToolProperty;
import hudson.util.FormValidation;
import hudson.util.XStream2;

Expand Down Expand Up @@ -205,6 +205,22 @@ public String getProgId() {
return progId;
}

/**
* Gets the programmatic identifier from tool properties.
*
* @return the progId, default progId if tool property does not exist
*/
public int getTimeout() {
int timeout;
final ETToolProperty toolProperty = getProperties().get(ETToolProperty.class);
if (toolProperty != null) {
timeout = toolProperty.getTimeout();
} else {
timeout = ETToolProperty.DescriptorImpl.getDefaultTimeout();
}
return timeout;
}

/**
* DescriptorImpl of {@link ETInstallation}.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2017 TraceTronic GmbH
* Copyright (c) 2015-2018 TraceTronic GmbH
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -48,15 +48,17 @@ public abstract class AbstractTestObject extends ETComDispatch {

/**
* Instantiates a new {@link AbstractTestObject}.
*
*
* This constructor is used instead of a case operation to turn a Dispatch object into a wider object - it must
* exist in every wrapper class whose instances may be returned from method calls wrapped in VT_DISPATCH Variants.
*
* @param dispatch
* the dispatch
* @param useTimeout
* specifies whether to apply timeout
*/
public AbstractTestObject(final Dispatch dispatch) {
super(dispatch);
public AbstractTestObject(final Dispatch dispatch, final boolean useTimeout) {
super(dispatch, useTimeout);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016 TraceTronic GmbH
* Copyright (c) 2015-2018 TraceTronic GmbH
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -42,15 +42,17 @@ public class Constant extends AbstractTestObject implements ComConstant {

/**
* Instantiates a new {@link Constant}.
*
*
* This constructor is used instead of a case operation to turn a Dispatch object into a wider object - it must
* exist in every wrapper class whose instances may be returned from method calls wrapped in VT_DISPATCH Variants.
*
* @param dispatch
* the dispatch
* @param useTimeout
* specifies whether to apply timeout
*/
public Constant(final Dispatch dispatch) {
super(dispatch);
public Constant(final Dispatch dispatch, final boolean useTimeout) {
super(dispatch, useTimeout);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016 TraceTronic GmbH
* Copyright (c) 2015-2018 TraceTronic GmbH
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -44,15 +44,17 @@ public class Constants extends AbstractTestObject implements ComConstants {

/**
* Instantiates a new {@link Constants}.
*
*
* This constructor is used instead of a case operation to turn a Dispatch object into a wider object - it must
* exist in every wrapper class whose instances may be returned from method calls wrapped in VT_DISPATCH Variants.
*
* @param dispatch
* the dispatch
* @param useTimeout
* specifies whether to apply timeout
*/
public Constants(final Dispatch dispatch) {
super(dispatch);
public Constants(final Dispatch dispatch, final boolean useTimeout) {
super(dispatch, useTimeout);
}

@Override
Expand All @@ -62,12 +64,12 @@ public int getCount() throws ETComException {

@Override
public ComConstant item(final int id) throws ETComException {
return new Constant(performRequest("Item", new Variant(id)).toDispatch());
return new Constant(performRequest("Item", new Variant(id)).toDispatch(), useTimeout());
}

@Override
public ComConstant item(final String name) throws ETComException {
return new Constant(performRequest("Item", new Variant(name)).toDispatch());
return new Constant(performRequest("Item", new Variant(name)).toDispatch(), useTimeout());
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2017 TraceTronic GmbH
* Copyright (c) 2015-2018 TraceTronic GmbH
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -35,6 +35,7 @@

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.JacobException;
import com.jacob.com.Variant;

import de.tracetronic.jenkins.plugins.ecutest.wrapper.com.api.ComApplication;
Expand Down Expand Up @@ -65,6 +66,8 @@ public class ETComClient implements ComApplication, AutoCloseable {
*/
private boolean releaseDispatch;

private boolean timeoutEnabled;

/**
* Instantiates a new {@link ETComClient} by initializing the {@link ETComDispatch} with the configured COM
* settings.
Expand Down Expand Up @@ -132,6 +135,47 @@ public ETComClient(final String progId, final int timeout) throws ETComException
* in case of a COM exception
*/
private void initDispatch(final String progId) throws ETComException {
final ETComProperty properties = ETComProperty.getInstance();
final int timeout = properties.getTimeout();
if (timeout == 0) {
timeoutEnabled = false;
initSTA(progId);
} else {
timeoutEnabled = true;
initMTA(progId);
}
}

/**
* Initializes the a single-threaded {@link COMThread} and sets the {@link ETComDispatch} instance using the default
* program id returned from the {@link ActiveXComponent}.
*
* @param progId
* the programmatic identifier
* @throws ETComException
* in case of a COM exception
*/
private void initSTA(final String progId) throws ETComException {
try {
ComThread.InitSTA();
final ActiveXComponent component = new ActiveXComponent(StringUtils.isEmpty(progId) ?
ETComProperty.DEFAULT_PROG_ID : progId);
dispatch = new ETComDispatch(component.getObject(), false);
} catch (final JacobException e) {
throw new ETComException(e.getMessage(), e);
}
}

/**
* Initializes the a single-threaded {@link COMThread} and sets the {@link ETComDispatch} instance using the default
* program id returned from the {@link ActiveXComponent}.
*
* @param progId
* the programmatic identifier
* @throws ETComException
* in case of a COM exception
*/
private void initMTA(final String progId) throws ETComException {
try {
ComThread.InitMTA();
releaseDispatch = false;
Expand Down Expand Up @@ -194,34 +238,67 @@ private void waitForConnection(final int timeout) throws ETComException {

@Override
public void close() {
releaseDispatch = true;
ComThread.quitMainSTA();
if (timeoutEnabled) {
releaseDispatch = true;
ComThread.quitMainSTA();
} else {
try {
releaseDispatch();
} catch (final ETComException e) {
// noop
} finally {
ComThread.Release();
}
}
}

@SuppressWarnings("checkstyle:superfinalize")
@Override
protected void finalize() {
// noop to prevent JVM crash
protected void finalize() throws Throwable {
if (!timeoutEnabled) {
try {
releaseDispatch();
} finally {
ComThread.Release();
super.finalize();
}
} // else noop to prevent JVM crash
}

/**
* Releases the {@link Dispatch}.
*
* @throws ETComException
* in case of a COM exception
*/
private void releaseDispatch() throws ETComException {
if (dispatch != null) {
try {
dispatch.safeRelease();
} catch (final JacobException e) {
throw new ETComException(e.getMessage(), e);
}
}
}

@Override
public ComTestEnvironment start() throws ETComException {
return new TestEnvironment(dispatch.performDirectRequest("Start").toDispatch());
return new TestEnvironment(dispatch.performDirectRequest("Start").toDispatch(), timeoutEnabled);
}

@Override
public ComTestEnvironment stop() throws ETComException {
return new TestEnvironment(dispatch.performDirectRequest("Stop").toDispatch());
return new TestEnvironment(dispatch.performDirectRequest("Stop").toDispatch(), timeoutEnabled);
}

@Override
public ComTestEnvironment getTestEnvironment() throws ETComException {
return new TestEnvironment(dispatch.performRequest("GetTestEnvironment").toDispatch());
return new TestEnvironment(dispatch.performRequest("GetTestEnvironment").toDispatch(), timeoutEnabled);
}

@Override
public ComTestManagement getTestManagement() throws ETComException {
return new TestManagement(dispatch.performRequest("GetTestManagementModule").toDispatch());
return new TestManagement(dispatch.performRequest("GetTestManagementModule").toDispatch(), timeoutEnabled);
}

@Override
Expand Down Expand Up @@ -251,7 +328,7 @@ public boolean exit() throws ETComException {

@Override
public ComPackage openPackage(final String path) throws ETComException {
return new Package(dispatch.performRequest("OpenPackage", new Variant(path)).toDispatch());
return new Package(dispatch.performRequest("OpenPackage", new Variant(path)).toDispatch(), timeoutEnabled);
}

@Override
Expand All @@ -277,7 +354,7 @@ public ComProject openProject(final String path) throws ETComException {
public ComProject openProject(final String path, final boolean execInCurrentPkgDir,
final String filterExpression) throws ETComException {
return new Project(dispatch.performRequest("OpenProject", new Variant(path),
new Variant(execInCurrentPkgDir), new Variant(filterExpression)).toDispatch());
new Variant(execInCurrentPkgDir), new Variant(filterExpression)).toDispatch(), timeoutEnabled);
}

@Override
Expand All @@ -304,12 +381,14 @@ public boolean openTestConfiguration(final String path) throws ETComException {

@Override
public ComTestConfiguration getCurrentTestConfiguration() throws ETComException {
return new TestConfiguration(dispatch.performRequest("GetCurrentTestConfiguration").toDispatch());
return new TestConfiguration(dispatch.performRequest("GetCurrentTestConfiguration").toDispatch(),
timeoutEnabled);
}

@Override
public ComTestBenchConfiguration getCurrentTestBenchConfiguration() throws ETComException {
return new TestBenchConfiguration(dispatch.performRequest("GetCurrentTestbenchConfiguration").toDispatch());
return new TestBenchConfiguration(dispatch.performRequest("GetCurrentTestbenchConfiguration").toDispatch(),
timeoutEnabled);
}

@Override
Expand Down Expand Up @@ -346,7 +425,7 @@ public void run() {
try {
ComThread.InitMTA();
component = new ActiveXComponent(progId);
dispatch = new ETComDispatch(component.getObject());
dispatch = new ETComDispatch(component.getObject(), true);
while (!dispatch.isAttached()) {
sleep(100L);
}
Expand Down
Loading

0 comments on commit ed1f244

Please sign in to comment.