-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3 Added abstract processor component
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...ommunication/src/main/java/com/incquerylabs/iot/processor/AbstractProcessorComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.incquerylabs.iot.processor; | ||
|
||
import com.incquerylabs.iot.communication.IAddress; | ||
import com.incquerylabs.iot.communication.ISubscriberCallback; | ||
import com.incquerylabs.iot.communication.PublisherPool; | ||
import com.incquerylabs.iot.communication.SubscriberPool; | ||
import com.incquerylabs.iot.communication.exception.PoolNotInitializedException; | ||
|
||
public class AbstractProcessorComponent implements ISubscriberCallback { | ||
|
||
IAddress sourceAddress; | ||
IAddress targetAddress; | ||
|
||
IDataProcessor processor; | ||
|
||
public AbstractProcessorComponent(IAddress sourceAddress, IAddress targetAddress, IDataProcessor processor) throws PoolNotInitializedException { | ||
|
||
this.sourceAddress = sourceAddress; | ||
this.targetAddress = targetAddress; | ||
|
||
processor = this.processor; | ||
|
||
SubscriberPool.getInstance().registerCallback(sourceAddress, this); | ||
} | ||
|
||
@Override | ||
public void messageArrived(IAddress address, byte[] data) { | ||
try { | ||
PublisherPool.getInstance().next(targetAddress).publish(processor.process(data), 0); | ||
} catch (PoolNotInitializedException e) { | ||
// TODO Logging ... | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...rylabs.iot.communication/src/main/java/com/incquerylabs/iot/processor/IDataProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.incquerylabs.iot.processor; | ||
|
||
public interface IDataProcessor { | ||
|
||
public byte[] process(byte[] data); | ||
|
||
} |