Skip to content

Commit 38d3a44

Browse files
committed
cleaned up some comments
added more tests, mockito
1 parent ee68c43 commit 38d3a44

23 files changed

+287
-214
lines changed

README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<!--[![Build Status](https://travis-ci.org/java-native-access/jna.svg?branch=master)](https://travis-ci.org/java-native-access/jna)-->
22

3-
# mm2python
3+
# org.mm2python
44
micro-manager 2.0 plugin that enables python control using Py4j remote procedure calls and IPC data transfer using memory mapped files
55

66
# dependencies
7-
mm2python is a plugin for the open-source microscopy control project Micro-Manager (https://micro-manager.org/) (https://github.com/micro-manager/micro-manager)
7+
org.mm2python is a plugin for the open-source microscopy control project Micro-Manager (https://micro-manager.org/) (https://github.com/micro-manager/micro-manager)
88
Please download and install version 2.0 from that site.
99

10-
mm2python depends on the Py4j project (https://www.py4j.org/). It is included as a dependency in the gradle build
10+
org.mm2python depends on the Py4j project (https://www.py4j.org/). It is included as a dependency in the gradle build
1111

1212
# getting started
1313
For micro-manager users:
14-
> copy the mm2python .jar file from build/libs folder to your micro-manager plugin directory.
14+
> copy the org.mm2python .jar file from build/libs folder to your micro-manager plugin directory.
1515
> The next time you start micro-manager, it should be selectable from the menu.
1616
1717
For developers:
18-
> mm2python uses the gradle build system to manage tests, dependencies and build.
18+
> org.mm2python uses the gradle build system to manage tests, dependencies and build.
1919
>
2020
> Additionally, it was developed in IntelliJ and includes .idea files to help manage debugging configurations.
2121
> The package .jar can be built by running the "Jar" configuration. Then that .jar can be copied to your micro-manager directory by running "copyCoreToMM" configuration.
@@ -25,7 +25,7 @@ For developers:
2525
>
2626
2727
# how to use
28-
mm2python has a simple UI with three tabs:
28+
org.mm2python has a simple UI with three tabs:
2929
> 1) Main Pane: Contains a console to display events. Initiate the bridge to python (using py4j) by clicking the "create python bridge" button. Initiate the event monitor to track data generation by clicking the "START monitor" button
3030
3131
> 2) Configuration: Currently, there is only one implemented messenger interface: Py4j. You can select one of two temp-file management systems: fixed or dynamic.
@@ -48,7 +48,7 @@ For most users, you will simply use default values. Then the only need is to cl
4848
> gate = gateway.entry_point
4949
> ```
5050
>
51-
> 3 - to access data using mm2python (method 1):
51+
> 3 - to access data using org.mm2python (method 1):
5252
> ``` buildoutcfg
5353
> # if you want the newest data
5454
> meta = gate.getLastMeta()
@@ -63,7 +63,7 @@ For most users, you will simply use default values. Then the only need is to cl
6363
> ```
6464
> "dat" is an ndarray-like object that can be used interchangeably with numpy arrays.
6565
>
66-
> 4 - to access data using mm2python (method 2):
66+
> 4 - to access data using org.mm2python (method 2):
6767
> ``` buildoutcfg
6868
> # to retrieve any data based on coordinates, or subset of coordinates, use the builder
6969
> paramBuilder = gate.getParameterBuilder()
@@ -107,8 +107,8 @@ For most users, you will simply use default values. Then the only need is to cl
107107
> Be careful to use appropriate types when passing values. Most micro-manager methods require float.
108108
109109
# about
110-
> clicking "START monitor" causes mm2python to register for some global and datastore events (https://micro-manager.org/wiki/Version_2.0_API_Events).
111-
> Every time a "New Image Event" occurs, mm2python pulls a new thread to:
110+
> clicking "START monitor" causes org.mm2python to register for some global and datastore events (https://micro-manager.org/wiki/Version_2.0_API_Events).
111+
> Every time a "New Image Event" occurs, org.mm2python pulls a new thread to:
112112
> 1) create a MetaDataStore object that contains coordinate and additional information.
113113
> 2) write a memory mapped file, representing this data's location in system memory, to disk.
114114
> 3) write the MetaDataStore object in 1 to a concurrent hashmap and to a concurrent linked deque

build.gradle

+18-9
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,35 @@ dependencies {
8181
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
8282
implementation 'com.google.guava:guava:23.0'
8383

84+
testImplementation 'org.mockito:mockito-inline:2.13.0'
85+
8486
// JUnit 5
8587
compile group: 'org.junit.platform', name: 'junit-platform-commons', version: '1.2.0'
8688
compile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.2.0'
8789
compile group: 'org.junit.vintage', name: 'junit-vintage-engine', version: '5.2.0'
8890

91+
// Mockito
92+
compile group: 'org.mockito', name: 'mockito-core', version: '3.0.0'
93+
// compile group: 'org.mockito', name: 'mockito-junit-jupiter', version: '3.0.0'
94+
95+
// PowerMock
96+
// compile group: 'org.powermock', name: 'powermock-api-mockito', version: '1.7.4'
97+
// compile group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.2'
98+
99+
89100
// Micromanager core jars
90101
// somehow, micro-manager depends critically on this distributed scijava .jar
91102
compile fileTree(include: ['MMCoreJ.jar', 'MMJ_.jar', 'scijava-common-2.46.0.jar'], exclude: 'mm2Python.jar', dir: core_plugin_path)
103+
compile fileTree(include: ['ij.jar'], dir: app_path)
92104

93105
//zeroMQ
94-
// compile group: 'org.zeromq', name: 'jzmq', version: '2.1.0'
95-
96-
//scijava-common
97-
// compile group: 'org.scijava', name: 'scijava-common', version: '2.46.0'
98-
// core_libs group: 'org.scijava', name: 'scijava-common', version: '2.46.0'
106+
// compile group: 'org.zeromq', name: 'jeromq', version: '0.5.1'
99107

100108
//Py4J
101109
compile group: 'net.sf.py4j', name: 'py4j', version: '0.10.8.1'
102110
core_libs group: 'net.sf.py4j', name: 'py4j', version: '0.10.8.1'
103111

104-
// IntelliJ mm2python.UI Designer
112+
// IntelliJ org.mm2python.UI Designer
105113
compile group: 'com.intellij', name: 'forms_rt', version: '7.0.3'
106114
core_libs group: 'com.intellij', name: 'forms_rt', version: '7.0.3'
107115

@@ -127,11 +135,11 @@ jar {
127135

128136
task copyCoreToMM(type: Copy) {
129137
if(OperatingSystem.current().isMacOsX()) {
130-
from 'build/libs/mm2Python.jar'
138+
from 'build/libs/mm2python.jar'
131139
into app_path + "/plugins/Micro-Manager"
132140
}
133141
else if(OperatingSystem.current().isWindows()) {
134-
from 'build/libs/mm2Python.jar'
142+
from 'build/libs/mm2python.jar'
135143
into app_path + "\\plugins\\Micro-Manager"
136144
} else {
137145
println "unsupported OS"
@@ -142,7 +150,7 @@ task copyCoreToMM(type: Copy) {
142150
// PUBLISHING
143151

144152
archivesBaseName = 'mm2python'
145-
group = 'org.bryantchhun'
153+
group = 'bryantchhun'
146154
version = '0.0.1'
147155
description = 'desc. for mm2python'
148156

@@ -158,6 +166,7 @@ publishing {
158166
}
159167

160168
bintray {
169+
// DO NOT PUT YOUR KEY HERE. Set your computer's system environment variable instead.
161170
user = System.getenv('BINTRAY_USER')
162171
key = System.getenv('BINTRAY_KEY')
163172
publications = ['MyPublication']

build/libs/mm2python.jar

-1.07 KB
Binary file not shown.

examples/python_basic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from py4j.java_gateway import JavaGateway, GatewayParameters
55
import numpy as np
66

7-
# connect to mm2python
7+
# connect to org.mm2python
88
gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_field=True))
99

1010
# link to class
@@ -41,7 +41,7 @@
4141

4242

4343
# ===========================================
44-
# ===== access mm2python MetaDataStores =====
44+
# ===== access org.mm2python MetaDataStores =====
4545
# ===========================================
4646

4747
# retrieve MetaData object for the most recent image

src/main/java/org/mm2python/DataStructures/Queues/DynamicMemMapReferenceQueue.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ private static void createDynamicMemMapStore() {
8686
}
8787

8888
// if called before getCurrentBuffer and positionQueue is empty, will fail.
89-
public static int getCurrentPosition() {
89+
public int getCurrentPosition() {
9090
return positions.remove();
9191
}
9292

93-
public static boolean isEmpty() {
93+
public boolean isEmpty() {
9494
return positions.isEmpty();
9595
}
9696

97-
public static MappedByteBuffer getCurrentBuffer() {
97+
public MappedByteBuffer getCurrentBuffer() {
9898
if(isEmpty()) {
9999
createDynamicMemMapStore();
100100
return current_buf;
@@ -103,11 +103,11 @@ public static MappedByteBuffer getCurrentBuffer() {
103103
}
104104
}
105105

106-
public static int getCurrentByteLength() {
106+
public int getCurrentByteLength() {
107107
return bytelength;
108108
}
109109

110-
public static String getCurrentFileName() {
110+
public String getCurrentFileName() {
111111
return dynamicMapname;
112112
}
113113

src/main/java/org/mm2python/DataStructures/Queues/FixedMemMapReferenceQueue.java

+6-19
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class FixedMemMapReferenceQueue {
2323

2424
private static Queue<MappedByteBuffer> mmap_buffer_queue = new ConcurrentLinkedDeque<>();
2525

26-
public static void resetQueue() {
26+
public static void resetQueues() {
2727
mmap_filename_queue.clear();
2828
mmap_buffer_queue.clear();
2929
}
@@ -42,17 +42,15 @@ public static void createFileNames(int num) throws FileNotFoundException {
4242
}
4343

4444
// create num amount of blank mmaps
45-
4645
if (Constants.getFixedMemMap()) {
4746
for (int i = 0; i < num; i++) {
4847
String fixedMapName = Constants.tempFilePath + "/mmap_fixed_" + i+".dat";
4948

5049
// write filename
51-
// writeBlankToMemMap(fixedMapName, bytelength);
52-
putMemMapQueue(fixedMapName);
50+
mmap_filename_queue.add(fixedMapName);
5351

5452
MappedByteBuffer buf = initializeMemMapBuffers(fixedMapName, bytelength);
55-
putMemMapBufferQueue(buf);
53+
mmap_buffer_queue.add(buf);
5654

5755
}
5856
}
@@ -64,7 +62,7 @@ public static void createFileNames(int num) throws FileNotFoundException {
6462
* check if is empty. Should never be empty
6563
* @return : boolean
6664
*/
67-
public static boolean nextFileNameExists() {
65+
public boolean nextFileNameExists() {
6866
return !mmap_filename_queue.isEmpty();
6967
}
7068

@@ -73,7 +71,7 @@ public static boolean nextFileNameExists() {
7371
* for FILENAME
7472
* @return : String, head value
7573
*/
76-
public static String getNextFileName() {
74+
public String getNextFileName() {
7775
String next = mmap_filename_queue.poll();
7876
mmap_filename_queue.offer(next);
7977
return next;
@@ -84,23 +82,12 @@ public static String getNextFileName() {
8482
* for MAPPED BYTE BUFFER
8583
* @return : MappedByteBuffer
8684
*/
87-
public static MappedByteBuffer getNextBuffer() {
85+
public MappedByteBuffer getNextBuffer() {
8886
MappedByteBuffer buf = mmap_buffer_queue.poll();
8987
mmap_buffer_queue.offer(buf);
9088
return buf;
9189
}
9290

93-
// =================== SETTERS for filename, buffer ===============
94-
95-
96-
private static void putMemMapQueue(String mmap) {
97-
mmap_filename_queue.add(mmap);
98-
}
99-
100-
private static void putMemMapBufferQueue(MappedByteBuffer buf) {
101-
mmap_buffer_queue.add(buf);
102-
}
103-
10491
// =============== WRITE TO FILE METHODS ==================
10592

10693
/**

src/main/java/org/mm2python/DataStructures/Queues/MDSQueue.java

+2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ public static boolean isQueueEmpty() {
4242

4343
public MetaDataStore getFirstMDS() {
4444
// should we use takeFirst()? This will wait till mds available, while poll returns null
45+
// poll takes and removes
4546
return mdsQueue.pollFirst();
4647
}
4748

4849
public MetaDataStore getLastMDS() {
4950
// should we use takeLast()? This will wait till mds available, while poll returns null
51+
// poll takes and removes
5052
return mdsQueue.pollLast();
5153
}
5254

src/main/java/org/mm2python/MPIMethod/Kafka/Kafka.java

-14
This file was deleted.

src/main/java/org/mm2python/MPIMethod/OpenMPI/Horovod.java

-18
This file was deleted.

src/main/java/org/mm2python/MPIMethod/OpenMPI/OpenMPI.java

-4
This file was deleted.

src/main/java/org/mm2python/MPIMethod/Py4J/Py4J.java

+24-19
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ public class Py4J implements messengerInterface {
2222
private static Studio mm;
2323
private static GatewayServer gatewayServer;
2424

25+
/**
26+
* Constructor sets classloading strategy.
27+
* micro-manager plugin system has its own classloading strategy, which interferes with py4j
28+
* @param mm_ : Studio
29+
*/
2530
public Py4J(Studio mm_) {
2631
mm = mm_;
2732
RootClassLoadingStrategy rmmClassLoader = new RootClassLoadingStrategy();
2833
ReflectionUtil.setClassLoadingStrategy(rmmClassLoader);
2934
}
3035

31-
@Override
32-
public void startConnection(int port) {
33-
gatewayServer = new GatewayServer(new Py4JEntryPoint(mm), port);
34-
gatewayServer.start();
35-
36-
reporter.set_report_area(true, true, true,"Gateway Started at IP:port = "+gatewayServer.getAddress()+":"+gatewayServer.getPort());
37-
}
38-
36+
/**
37+
* Open ports using py4j for python process
38+
*/
3939
@Override
4040
public void startConnection() {
4141
gatewayServer = new GatewayServer(new Py4JEntryPoint(mm));
@@ -44,19 +44,24 @@ public void startConnection() {
4444
Constants.ports.add(port);
4545
reporter.set_report_area(true, true, true,"Gateway Started at IP:port = "+gatewayServer.getAddress()+":"+gatewayServer.getPort());
4646
}
47-
47+
48+
/**
49+
* close default port
50+
*/
4851
@Override
49-
public void stopConnection(int port) {
52+
public void stopConnection() {
5053
gatewayServer.shutdown();
51-
reporter.set_report_area(true, true, true, String.format("Gateway at port %04d shut down", port));
54+
reporter.set_report_area(true, true, true, "Gateway at default port shut down");
5255
}
53-
54-
@Override
55-
public void stopConnection() {
56-
Constants.ports.stream().forEach((port) -> {
57-
gatewayServer.shutdown();
58-
reporter.set_report_area(true, true, true, String.format("Gateway at port %04d shut down", port));
59-
});
6056

61-
}
57+
// /**
58+
// * close ports for
59+
// * @param port
60+
// */
61+
// @Override
62+
// public void stopConnection(int port) {
63+
// gatewayServer.shutdown();
64+
// reporter.set_report_area(true, true, true, String.format("Gateway at port %04d shut down", port));
65+
// }
66+
6267
}

src/main/java/org/mm2python/MPIMethod/gRPC/gRPC.java

-4
This file was deleted.

0 commit comments

Comments
 (0)