Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Feat/keyp 108 plugin lifecycle management #344

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
********************************************************************************/
package org.eclipse.keyple.plugin.android.nfc

import org.eclipse.keyple.core.seproxy.AbstractPluginFactory
import org.eclipse.keyple.core.seproxy.PluginFactory
import org.eclipse.keyple.core.seproxy.ReaderPlugin

class AndroidNfcPluginFactory : AbstractPluginFactory() {
class AndroidNfcPluginFactory : PluginFactory {

override fun getPluginName(): String {
return AndroidNfcPlugin.PLUGIN_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import androidx.annotation.VisibleForTesting
import org.eclipse.keyple.core.seproxy.AbstractPluginFactory
import org.eclipse.keyple.core.seproxy.PluginFactory
import org.eclipse.keyple.core.seproxy.ReaderPlugin
import org.eclipse.keyple.core.seproxy.exception.KeyplePluginInstantiationException

/**
* Build asynchronously the Android OMAPI plugin.
* Platform incompabilities are not managed
*/
class AndroidOmapiPluginFactory(private val context: Context) : AbstractPluginFactory() {
class AndroidOmapiPluginFactory(private val context: Context) : PluginFactory {

private var sdkVersion: Int = Build.VERSION.SDK_INT

Expand Down
10 changes: 5 additions & 5 deletions docs/img/KeypleCore-1-SE_Proxy-PluginSetting.iuml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ package org.eclipse.keyple.core.seproxy #FFFFFF {
+class "<b>final</b> SeProxyService" as SeProxyService << Singleton >> {
+{static}SeProxyService getInstance()
+String getVersion()
+registerPlugin(AbstractPluginFactory pluginFactory)
+registerPlugin(PluginFactory pluginFactory)
+boolean isRegistered(String pluginName)
+boolean unregisterPlugin(String pluginName)
+ReaderPlugin getPlugin(String name)
+SortedSet<ReaderPlugin> getPlugins()
}

+abstract AbstractPluginFactory {
+abstract PluginFactory {
{abstract} #String getPluginName()
{abstract} #ReaderPlugin getPluginInstance()
}
Expand All @@ -31,9 +31,9 @@ package org.eclipse.keyple.core.seproxy #FFFFFF {
}

SeProxyService "1" *-down-> "*" ReaderPlugin : plugins
SeProxyService "1" *--> "*" AbstractPluginFactory : registers
SeProxyService "1" *--> "*" PluginFactory : registers
ReaderPlugin "1" *-right-> "*" SeReader : readers
AbstractPluginFactory "1" -right-> "1" ReaderPlugin : creates
PluginFactory "1" -right-> "1" ReaderPlugin : creates
}

package plugin.specific #FFCCFF {
Expand Down Expand Up @@ -63,7 +63,7 @@ package plugin.specific #FFCCFF {
}
}

AbstractPluginFactory <|-- SpecificPluginFactory : extends
PluginFactory <|-- SpecificPluginFactory : extends
ReaderPlugin <|-- SpecificPlugin : extends
SeReader <|-- SpecificReader : extends

Expand Down
20 changes: 10 additions & 10 deletions docs/img/KeypleCore-1-SE_Proxy-PluginSetting.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/img/KeypleCore-2-SE_Proxy-ReaderAccess.iuml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package seproxy #FFFFFF {
+class "<b>final</b> SeProxyService" as SeProxyService << Singleton >> {
+{static}SeProxyService getInstance()
+String getVersion()
+registerPlugin(AbstractPluginFactory pluginFactory)
+registerPlugin(PluginFactory pluginFactory)
+boolean isRegistered(String pluginName)
+boolean unregisterPlugin(String pluginName)
+ReaderPlugin getPlugin(String name)
Expand Down
4 changes: 2 additions & 2 deletions docs/img/KeypleCore-2-SE_Proxy-ReaderAccess.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/img/KeypleCore-3-SE_Proxy-ObserverPattern.iuml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package org.eclipse.keyple.core.seproxy #FFFFFF {
+class "<b>final</b> SeProxyService" as SeProxyService << Singleton >> {
+{static}SeProxyService getInstance()
+String getVersion()
+registerPlugin(AbstractPluginFactory pluginFactory)
+registerPlugin(PluginFactory pluginFactory)
+boolean isRegistered(String pluginName)
+boolean unregisterPlugin(String pluginName)
+ReaderPlugin getPlugin(String name)
Expand Down
4 changes: 2 additions & 2 deletions docs/img/KeypleCore-3-SE_Proxy-ObserverPattern.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

import org.eclipse.keyple.core.seproxy.exception.KeyplePluginInstantiationException;

public abstract class AbstractPluginFactory {
public interface PluginFactory {

/**
* Retrieve the name of the plugin that will be instantiated by this factory (can be static or
* dynamic)
*
* @return pluginName
*/
public abstract String getPluginName();
String getPluginName();


/**
Expand All @@ -31,7 +31,7 @@ public abstract class AbstractPluginFactory {
* @throws KeyplePluginInstantiationException if instantiation failed, mostly when the third
* party library which manages the Se Reader interface is not ready
*/
protected abstract ReaderPlugin getPluginInstance() throws KeyplePluginInstantiationException;
ReaderPlugin getPluginInstance() throws KeyplePluginInstantiationException;


}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static SeProxyService getInstance() {
* @throws KeyplePluginInstantiationException if instantiation failed
* @return ReaderPlugin : registered reader plugin
*/
public ReaderPlugin registerPlugin(AbstractPluginFactory pluginFactory)
public ReaderPlugin registerPlugin(PluginFactory pluginFactory)
throws KeyplePluginInstantiationException {
if (pluginFactory == null) {
throw new IllegalArgumentException("Factory must not be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;
import org.eclipse.keyple.core.seproxy.event.ObservablePlugin;
import org.eclipse.keyple.core.seproxy.event.PluginEvent;
import org.eclipse.keyple.core.seproxy.exception.KeypleReaderException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -38,8 +39,9 @@ public abstract class AbstractObservablePlugin extends AbstractPlugin
* Instantiates a observable plugin.
*
* @param name name of the plugin
* @throws KeypleReaderException when an issue is raised with reader
*/
protected AbstractObservablePlugin(String name) {
protected AbstractObservablePlugin(String name) throws KeypleReaderException {
super(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,14 @@ public abstract class AbstractPlugin extends AbstractSeProxyComponent implements
*
* Initialize the list of readers calling the abstract method initNativeReaders
*
* When readers initialisation failed, a KeypleRuntimeException is thrown
* When readers initialisation failed, a KeypleReaderException is thrown
*
* @param name name of the plugin
* @throws KeypleReaderException when an issue is raised with reader
*/
protected AbstractPlugin(String name) {
protected AbstractPlugin(String name) throws KeypleReaderException {
super(name);

try {
readers.addAll(initNativeReaders());
} catch (KeypleReaderException e) {
throw new KeypleRuntimeException("Could not instantiate readers in plugin constructor",
e);
}
readers.addAll(initNativeReaders());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public abstract class AbstractThreadedObservablePlugin extends AbstractObservabl
* Instantiates a threaded observable plugin.
*
* @param name name of the plugin
* @throws KeypleReaderException when an issue is raised with reader
*/
protected AbstractThreadedObservablePlugin(String name) {
protected AbstractThreadedObservablePlugin(String name) throws KeypleReaderException {
super(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
********************************************************************************/
package org.eclipse.keyple.core.seproxy;

import org.eclipse.keyple.core.seproxy.exception.KeyplePluginInstantiationException;
import org.eclipse.keyple.core.seproxy.plugin.mock.MockAbstractThreadedPlugin;

public class MockObservablePluginFactory extends AbstractPluginFactory {
public class MockObservablePluginFactory implements PluginFactory {

private final String pluginName;

Expand All @@ -27,7 +28,11 @@ public String getPluginName() {
}

@Override
protected ReaderPlugin getPluginInstance() {
return new MockAbstractThreadedPlugin(pluginName);
public ReaderPlugin getPluginInstance() throws KeyplePluginInstantiationException {
try {
return new MockAbstractThreadedPlugin(pluginName);
} catch (Exception e) {
throw new KeyplePluginInstantiationException("Could not connect readers ", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.keyple.core.seproxy.exception.KeyplePluginInstantiationException;
import org.eclipse.keyple.core.seproxy.exception.KeyplePluginNotFoundException;
import org.eclipse.keyple.core.seproxy.exception.KeypleReaderException;
import org.eclipse.keyple.core.seproxy.plugin.AbstractPlugin;
import org.eclipse.keyple.core.seproxy.plugin.mock.MockAbstractThreadedPlugin;
import org.junit.Assert;
Expand All @@ -45,18 +46,20 @@ public class SeProxyServiceTest {

AbstractPlugin plugin1 = new MockAbstractThreadedPlugin(PLUGIN_NAME_1);

AbstractPlugin plugin2 = new MockAbstractThreadedPlugin(PLUGIN_NAME_2);;
AbstractPlugin plugin2 = new MockAbstractThreadedPlugin(PLUGIN_NAME_2);

@Mock
AbstractPluginFactory factory1;
PluginFactory factory1;

@Mock
AbstractPluginFactory factory2;
PluginFactory factory2;


static String PLUGIN_NAME_1 = "plugin1";
static String PLUGIN_NAME_2 = "plugin2";

public SeProxyServiceTest() throws KeypleReaderException {}
jeanpierrefortune marked this conversation as resolved.
Show resolved Hide resolved

@Before
public void setupBeforeEach() throws KeyplePluginInstantiationException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void setUp() {
* @throws Throwable
*/
@Test
public void addRemoveReadersMultiThreaded() throws InterruptedException {
public void addRemoveReadersMultiThreaded() throws Exception {
ReaderPlugin plugin = new BlankAbstractPlugin("addRemoveReadersMultiThreaded");
SortedSet<SeReader> readers = plugin.getReaders();
final CountDownLatch lock = new CountDownLatch(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.eclipse.keyple.core.CoreBaseTest;
import org.eclipse.keyple.core.seproxy.event.ObservablePlugin;
import org.eclipse.keyple.core.seproxy.event.PluginEvent;
import org.eclipse.keyple.core.seproxy.exception.KeypleRuntimeException;
import org.eclipse.keyple.core.seproxy.exception.KeypleReaderException;
import org.eclipse.keyple.core.seproxy.plugin.mock.BlankFailingPlugin;
import org.eclipse.keyple.core.seproxy.plugin.mock.MockAbstractThreadedPlugin;
import org.junit.Assert;
Expand All @@ -41,8 +41,8 @@ public void setUp() {
*
* @throws Throwable
*/
@Test(expected = KeypleRuntimeException.class)
public void instantiatePlugin() {
@Test(expected = KeypleReaderException.class)
public void instantiatePlugin() throws KeypleReaderException {
new BlankFailingPlugin("addObserverTest");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.SortedSet;
import java.util.TreeSet;
import org.eclipse.keyple.core.seproxy.SeReader;
import org.eclipse.keyple.core.seproxy.exception.KeypleReaderException;
import org.eclipse.keyple.core.seproxy.exception.KeypleReaderIOException;
import org.eclipse.keyple.core.seproxy.plugin.AbstractPlugin;

Expand All @@ -23,7 +24,7 @@
*/
public class BlankAbstractPlugin extends AbstractPlugin {

public BlankAbstractPlugin(String name) {
public BlankAbstractPlugin(String name) throws KeypleReaderException {
super(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Map;
import java.util.SortedSet;
import org.eclipse.keyple.core.seproxy.SeReader;
import org.eclipse.keyple.core.seproxy.exception.KeypleReaderException;
import org.eclipse.keyple.core.seproxy.exception.KeypleReaderIOException;
import org.eclipse.keyple.core.seproxy.exception.KeypleReaderNotFoundException;
import org.eclipse.keyple.core.seproxy.plugin.AbstractThreadedObservablePlugin;
Expand All @@ -23,7 +24,7 @@
*/
public class BlankFailingPlugin extends AbstractThreadedObservablePlugin {

public BlankFailingPlugin(String name) {
public BlankFailingPlugin(String name) throws KeypleReaderException {
super(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.SortedSet;
import java.util.TreeSet;
import org.eclipse.keyple.core.seproxy.SeReader;
import org.eclipse.keyple.core.seproxy.exception.KeypleReaderException;
import org.eclipse.keyple.core.seproxy.exception.KeypleReaderIOException;
import org.eclipse.keyple.core.seproxy.exception.KeypleReaderNotFoundException;
import org.eclipse.keyple.core.seproxy.plugin.AbstractReader;
Expand All @@ -23,7 +24,7 @@
public class MockAbstractThreadedPlugin extends AbstractThreadedObservablePlugin {


public MockAbstractThreadedPlugin(String name) {
public MockAbstractThreadedPlugin(String name) throws KeypleReaderException {
super(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
********************************************************************************/
package org.eclipse.keyple.plugin.pcsc;

import org.eclipse.keyple.core.seproxy.AbstractPluginFactory;
import org.eclipse.keyple.core.seproxy.PluginFactory;
import org.eclipse.keyple.core.seproxy.ReaderPlugin;
import org.eclipse.keyple.core.seproxy.exception.KeyplePluginInstantiationException;
import org.eclipse.keyple.core.seproxy.exception.KeypleRuntimeException;

/**
* Builds a {@link PcscPlugin}
*/
public class PcscPluginFactory extends AbstractPluginFactory {
public class PcscPluginFactory implements PluginFactory {

@Override
public String getPluginName() {
Expand All @@ -33,12 +32,12 @@ public String getPluginName() {
* @throws KeyplePluginInstantiationException if Smartcard.io library is not ready
*/
@Override
protected ReaderPlugin getPluginInstance() throws KeyplePluginInstantiationException {
public ReaderPlugin getPluginInstance() throws KeyplePluginInstantiationException {
try {
return PcscPluginImpl.getInstance();
} catch (KeypleRuntimeException e) {
} catch (Exception e) {
throw new KeyplePluginInstantiationException(
"Can not access Smartcard.io readers, check initNativeReaders trace", e);
"Can not access Smartcard.io readers, check createVirtualReader trace", e);
}
}
}