Add local message system

This commit is contained in:
Pablete1234 2017-02-22 08:22:59 +01:00
parent 467e73594f
commit 11b89e0dcb
No known key found for this signature in database
GPG Key ID: DAFF9A337EF9A5FA
3 changed files with 36 additions and 18 deletions

View File

@ -0,0 +1,35 @@
package tc.oc.api.whispers;
import com.google.common.reflect.TypeToken;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Inject;
import tc.oc.api.docs.PlayerId;
import tc.oc.api.docs.Whisper;
import tc.oc.api.docs.virtual.WhisperDoc;
import tc.oc.api.exceptions.NotFound;
import tc.oc.api.message.LocalMessageService;
import tc.oc.api.message.types.ModelUpdate;
import tc.oc.api.model.NullModelService;
public class LocalWhisperService extends NullModelService<Whisper, WhisperDoc.Partial> implements WhisperService {
@Inject private LocalMessageService queue;
@Override
public ListenableFuture<Whisper> forReply(PlayerId user) {
return Futures.immediateFailedFuture(new NotFound());
}
@Override
public ListenableFuture<Whisper> update(WhisperDoc.Partial partial) {
// Receives an Out object from WhisperDispatcher, and it implements Whisper, so we can just cast it.
if (partial instanceof Whisper) {
Whisper whisper = (Whisper) partial;
queue.receive((ModelUpdate<Whisper>) () -> whisper, new TypeToken<ModelUpdate<Whisper>>(){});
return Futures.immediateFuture(whisper);
}
return Futures.immediateFailedFuture(new NotFound());
}
}

View File

@ -1,17 +0,0 @@
package tc.oc.api.whispers;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import tc.oc.api.docs.PlayerId;
import tc.oc.api.docs.Whisper;
import tc.oc.api.docs.virtual.WhisperDoc;
import tc.oc.api.exceptions.NotFound;
import tc.oc.api.model.NullModelService;
public class NullWhisperService extends NullModelService<Whisper, WhisperDoc.Partial> implements WhisperService {
@Override
public ListenableFuture<Whisper> forReply(PlayerId user) {
return Futures.immediateFailedFuture(new NotFound());
}
}

View File

@ -15,7 +15,7 @@ public class WhisperModelManifest extends HybridManifest implements ModelBinders
});
OptionalBinder.newOptionalBinder(publicBinder(), WhisperService.class)
.setDefault().to(NullWhisperService.class);
.setDefault().to(LocalWhisperService.class);
}
}