- Timestamp:
- 07/04/13 20:29:50 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/communication/StateCallback.java
r85 r96 1 1 package com.framsticks.communication; 2 2 3 import com.framsticks.util.FramsticksException; 3 4 import com.framsticks.util.StateFunctor; 4 5 … … 6 7 * @author Piotr Sniegowski 7 8 */ 8 public abstract class StateCallback<C> implements ResponseCallback<C>, StateFunctor { 9 public abstract class StateCallback<C> extends ResponseCallback<C> implements StateFunctor { 10 11 12 protected StateFunctor wrapped; 13 14 public StateCallback(StateFunctor wrapped) { 15 this.wrapped = wrapped; 16 } 17 18 public StateCallback() { 19 this.wrapped = null; 20 } 21 22 protected StateFunctor move() { 23 assert wrapped != null; 24 StateFunctor result = wrapped; 25 wrapped = null; 26 return result; 27 } 28 29 protected abstract void callImpl(); 30 31 @Override 32 public final void call() { 33 try { 34 callImpl(); 35 } catch (FramsticksException e) { 36 handle(e); 37 return; 38 } 39 if (wrapped != null) { 40 wrapped.call(); 41 } 42 } 43 44 @Override 45 public void handle(FramsticksException exception) { 46 if (wrapped != null) { 47 wrapped.handle(exception); 48 return; 49 } 50 throw exception; 51 } 52 9 53 @Override 10 54 public void process(Response response) { 11 call(response.getOk() ? null : new Exception(response.getComment())); 55 if (response.getOk()) { 56 call(); 57 } else { 58 handle(new FramsticksException().msg("non-ok response").arg("comment", response.getComment())); 59 } 12 60 } 13 61 }
Note: See TracChangeset
for help on using the changeset viewer.