Skip to content

Commit dd05e0d

Browse files
committed
allow multiengine to setup new asapEngines
1 parent ef3dc46 commit dd05e0d

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

src/net/sharksystem/asap/MultiASAPEngineFS.java

+20-4
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,34 @@
2020
* That interface hides those different engines.
2121
*/
2222
public interface MultiASAPEngineFS {
23-
public static final long DEFAULT_MAX_PROCESSING_TIME = Long.MAX_VALUE;
23+
long DEFAULT_MAX_PROCESSING_TIME = Long.MAX_VALUE;
2424

25-
public ASAPEngine getEngineByFormat(CharSequence format) throws ASAPException, IOException;
25+
/**
26+
* get an existing engine
27+
* @param format
28+
* @return
29+
* @throws ASAPException engine does not exist
30+
* @throws IOException
31+
*/
32+
ASAPEngine getEngineByFormat(CharSequence format) throws ASAPException, IOException;
33+
34+
/**
35+
* create an engine for a given format / application name
36+
* @param format
37+
* @return
38+
* @throws ASAPException
39+
* @throws IOException
40+
*/
41+
ASAPEngine createEngineByFormat(CharSequence format) throws ASAPException, IOException;
2642

2743
ASAPChunkReceivedListener getListenerByFormat(CharSequence format) throws ASAPException;
2844

2945
/**
3046
* get or create engine for a given application - mainly means: setup folder
31-
* @param appName
47+
* @param format
3248
* @return
3349
*/
34-
ASAPEngine getASAPEngine(CharSequence appName, CharSequence format) throws IOException, ASAPException;
50+
ASAPEngine getASAPEngine(CharSequence format) throws IOException, ASAPException;
3551

3652
/**
3753
* handle that newly established connection to another ASAP peer

src/net/sharksystem/asap/MultiASAPEngineFS_Impl.java

+22-2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ public ASAPEngine getEngineByFormat(CharSequence format) throws ASAPException, I
140140
return asapEngine;
141141
}
142142

143+
@Override
144+
public ASAPEngine createEngineByFormat(CharSequence format) throws ASAPException, IOException {
145+
try {
146+
return this.getEngineByFormat(format);
147+
}
148+
catch(ASAPException e) {
149+
// does not exist yet
150+
}
151+
152+
String folderName = this.getEngineFolderByAppName(format);
153+
ASAPEngine asapEngine = this.getASAPEngine(format);
154+
this.folderMap.put(format, new EngineSetting(folderName, listener));
155+
156+
return asapEngine;
157+
}
158+
143159
@Override
144160
public ASAPChunkReceivedListener getListenerByFormat(CharSequence format) throws ASAPException {
145161
EngineSetting engineSetting = this.folderMap.get(format);
@@ -148,11 +164,15 @@ public ASAPChunkReceivedListener getListenerByFormat(CharSequence format) throws
148164
return engineSetting.listener;
149165
}
150166

167+
private String getEngineFolderByAppName(CharSequence appName) {
168+
return this.rootFolderName.toString() + "/" + appName;
169+
}
170+
151171
@Override
152-
public ASAPEngine getASAPEngine(CharSequence appName, CharSequence format)
172+
public ASAPEngine getASAPEngine(CharSequence format)
153173
throws IOException, ASAPException {
154174

155-
String foldername = this.rootFolderName.toString() + "/" + appName.toString();
175+
String foldername = this.getEngineFolderByAppName(format);
156176
// already exists?
157177
try {
158178
ASAPEngine existingASAPEngineFS = ASAPEngineFS.getExistingASAPEngineFS(foldername);

0 commit comments

Comments
 (0)