11package net .sharksystem .asap ;
22
3+ import net .sharksystem .asap .management .ASAPManagementMessage ;
4+ import net .sharksystem .asap .management .ASAPManagementStorage ;
35import net .sharksystem .asap .protocol .*;
46import net .sharksystem .asap .util .Log ;
57
911import java .util .ArrayList ;
1012import java .util .HashMap ;
1113import java .util .List ;
14+ import java .util .Set ;
1215
1316/**
1417 * That ASAPEngine manages exchange of stored messages with peers.
@@ -91,13 +94,20 @@ public CharSequence getExtra(CharSequence uri, String key) throws IOException {
9194 }
9295
9396 @ Override
94- public void createChannel (CharSequence urlTarget , List <CharSequence > recipients ) throws IOException , ASAPException {
95- this .setRecipients (urlTarget , recipients );
97+ public void createChannel (CharSequence uri , List <CharSequence > recipients ) throws IOException , ASAPException {
98+ this .createChannel (this .getOwner (), uri , recipients );
99+ }
100+
101+ @ Override
102+ public void createChannel (CharSequence owner , CharSequence uri , List <CharSequence > recipients )
103+ throws IOException , ASAPException {
104+
105+ this .setRecipients (uri , recipients );
106+ this .getASAPChannelImpl (uri ).setOwner (owner );
96107
97108 // inform recipients about that event
98109 if (this .isASAPManagementStorageSet ()) {
99- ASAPManagementStorage asapManagementStorage = this .getASAPManagementStorage ();
100- asapManagementStorage .addCreateClosedASAPChannelMessage (this .format , urlTarget , recipients );
110+ this .getASAPManagementStorage ().notifyChannelCreated (this .format , owner , uri , recipients );
101111 } else {
102112 System .out .println (this .getLogStart ()
103113 + "asap management storage not set - no propagation of channel creation" );
@@ -128,13 +138,13 @@ public boolean isASAPManagementStorageSet() {
128138 return this .asapManagementStorage != null ;
129139 }
130140
131- public void addCreateClosedASAPChannelMessage (CharSequence appName , CharSequence channelUri ,
132- List <CharSequence > recipients )
141+ public void notifyChannelCreated (CharSequence appName , CharSequence owner ,
142+ CharSequence uri , List <CharSequence > recipients )
133143 throws ASAPException , IOException {
134144
135145 byte [] createClosedASAPChannelMessage =
136146 ASAPManagementMessage .getCreateClosedASAPChannelMessage (
137- this . getOwner () , appName , channelUri , recipients );
147+ owner , appName , uri , recipients );
138148
139149 // put into create channel
140150 this .add (ASAPManagementStorage .ASAP_CREATE_CHANNEL , createClosedASAPChannelMessage );
@@ -149,7 +159,7 @@ public void setRecipients(CharSequence urlTarget, List<CharSequence> recipients)
149159 this .chunkStorage .getChunk (urlTarget , this .era ).setRecipients (recipients );
150160 }
151161
152- public List <CharSequence > getRecipients (CharSequence urlTarget ) throws IOException {
162+ public Set <CharSequence > getRecipients (CharSequence urlTarget ) throws IOException {
153163 return this .chunkStorage .getChunk (urlTarget , this .era ).getRecipients ();
154164 }
155165
@@ -201,6 +211,19 @@ public List<CharSequence> getChannelURIs() throws IOException {
201211 return uriList ;
202212 }
203213
214+ @ Override
215+ public ASAPChannel getChannel (CharSequence uri ) throws ASAPException , IOException {
216+ return this .getASAPChannelImpl (uri );
217+ }
218+
219+ private ASAPChannelImpl getASAPChannelImpl (CharSequence uri ) throws ASAPException , IOException {
220+ if (this .channelExists (uri )) {
221+ return new ASAPChannelImpl (this , uri );
222+ }
223+
224+ throw new ASAPException ("channel with does not exist: " + uri );
225+ }
226+
204227 @ Override
205228 public boolean channelExists (CharSequence uri ) throws IOException {
206229 return this .chunkStorage .existsChunk (uri , this .getEra ());
@@ -463,10 +486,6 @@ public void handleASAPAssimilate(ASAP_AssimilationPDU_1_0 asapAssimiliationPDU,
463486 }
464487 }
465488
466- private boolean isASAPManagementMessage (ASAP_PDU_1_0 asapPDU ) {
467- return asapPDU .getFormat ().equalsIgnoreCase (ASAP_1_0 .ASAP_MANAGEMENT_FORMAT );
468- }
469-
470489 public void handleASAPInterest (ASAP_Interest_PDU_1_0 asapInterest , ASAP_1_0 protocol , OutputStream os )
471490 throws ASAPException , IOException {
472491
@@ -612,7 +631,7 @@ private void sendChunks(CharSequence sender, String recipient, ASAPChunkStorage
612631
613632 // is not a public chunk
614633 if (!this .isPublic (chunk )) {
615- List <CharSequence > recipients = chunk .getRecipients ();
634+ Set <CharSequence > recipients = chunk .getRecipients ();
616635
617636 if (!recipients .contains (recipient )) {
618637 continue ;
0 commit comments