@@ -226,8 +226,8 @@ public class Layer<T> implements Persistable {
226
226
private Layer <Inference > previous ;
227
227
228
228
private transient List <Observer <Inference >> observers = new ArrayList <Observer <Inference >>();
229
- private transient CheckPointer < byte []> checkPointer ;
230
- private transient List <Observer <byte []>> checkPointObservers = new ArrayList <>();
229
+ private transient CheckPointOperator <?> checkPointOp ;
230
+ private transient List <Observer <byte []>> checkPointOpObservers = new ArrayList <>();
231
231
232
232
233
233
@@ -325,7 +325,7 @@ public Layer<T> postDeSerialize() {
325
325
factory = new FunctionFactory ();
326
326
factory .inference = old .inference .postSerialize (old .inference );
327
327
328
- checkPointObservers = new ArrayList <>();
328
+ checkPointOpObservers = new ArrayList <>();
329
329
330
330
if (sensor != null ) {
331
331
sensor .setLocalParameters (params );
@@ -404,7 +404,18 @@ public Layer(Parameters params, MultiEncoder e, SpatialPooler sp, TemporalMemory
404
404
(anomalyComputer == null ? "" : "Anomaly" ));
405
405
}
406
406
}
407
-
407
+
408
+ /**
409
+ * USED INTERNALLY, DO NOT CALL.
410
+ * @return
411
+ */
412
+ public CheckPointOp <byte []> delegateCheckPointCall () {
413
+ if (parentNetwork != null ) {
414
+ return parentNetwork .getCheckPointOperator ();
415
+ }
416
+ return null ;
417
+ }
418
+
408
419
/**
409
420
* Sets the parent region which contains this {@code Layer}
410
421
*
@@ -1426,9 +1437,9 @@ public int getMostProbableBucketIndex(String field, int step) {
1426
1437
return c .getMostProbableBucketIndex (step );
1427
1438
}
1428
1439
1429
- // ////////////////////////////////////////////////////////////
1430
- // PRIVATE METHODS AND CLASSES BELOW HERE //
1431
- // ////////////////////////////////////////////////////////////
1440
+ //////////////////////////////////////////////////////////////
1441
+ // PRIVATE METHODS AND CLASSES BELOW HERE //
1442
+ //////////////////////////////////////////////////////////////
1432
1443
/**
1433
1444
* Notify all subscribers through the delegate that stream processing has
1434
1445
* been completed or halted.
@@ -1639,7 +1650,7 @@ private Observable<ManualInput> resolveObservableSequence(T t) {
1639
1650
}
1640
1651
1641
1652
sequenceStart = sequenceStart .filter (m -> {
1642
- if (!checkPointObservers .isEmpty () && parentNetwork != null ) {
1653
+ if (!checkPointOpObservers .isEmpty () && parentNetwork != null ) {
1643
1654
// Execute check point logic
1644
1655
doCheckPoint ();
1645
1656
}
@@ -1656,21 +1667,21 @@ private Observable<ManualInput> resolveObservableSequence(T t) {
1656
1667
* Observers; then clears the list of Observers.
1657
1668
*/
1658
1669
private void doCheckPoint () {
1659
- byte [] bytes = parentNetwork .internalCheckPoint ();
1670
+ byte [] bytes = parentNetwork .internalCheckPointOp ();
1660
1671
1661
1672
if (bytes != null ) {
1662
1673
LOGGER .debug ("Layer [" + getName () + "] checkPointed file: " +
1663
- Network . serializer ( null , false ).getLastCheckPointFileName () + ", hc = " + Network . serializer ( null , false ). hashCode ());
1674
+ Persistence . get ( ).getLastCheckPointFileName ());
1664
1675
}else {
1665
1676
LOGGER .debug ("Layer [" + getName () + "] checkPoint F A I L E D at: " + (new DateTime ()));
1666
1677
}
1667
1678
1668
- for (Observer <byte []> o : checkPointObservers ) {
1679
+ for (Observer <byte []> o : checkPointOpObservers ) {
1669
1680
o .onNext (bytes );
1670
1681
o .onCompleted ();
1671
1682
}
1672
1683
1673
- checkPointObservers .clear ();
1684
+ checkPointOpObservers .clear ();
1674
1685
}
1675
1686
1676
1687
/**
@@ -2005,25 +2016,29 @@ public void run() {
2005
2016
}
2006
2017
2007
2018
/**
2008
- * Returns the pre-built subscribe function used to add subscribers (callers of
2009
- * {@link #checkPointer()}) to the check point observer notifications.
2010
- *
2011
- * @return the internal Observable used for post check point notifications.
2019
+ * Returns an {@link rx.Observable} operator that when subscribed to, invokes an operation
2020
+ * that stores the state of this {@code Network} while keeping the Network up and running.
2021
+ * The Network will be stored at the pre-configured location (in binary form only, not JSON).
2022
+ *
2023
+ * @param network the {@link Network} to check point.
2024
+ * @return the {@link CheckPointOp} operator
2012
2025
*/
2013
- CheckPointer <byte []> checkPointer () {
2014
- if (checkPointer == null ) {
2015
- checkPointer = new CheckPointerImpl <byte []>(Layer .this );
2026
+ @ SuppressWarnings ("unchecked" )
2027
+ CheckPointOp <byte []> getCheckPointOperator () {
2028
+ if (checkPointOp == null ) {
2029
+ checkPointOp = new CheckPointOperator <byte []>(Layer .this );
2016
2030
}
2017
- return checkPointer ;
2031
+ return ( CheckPointOp < byte []>) checkPointOp ;
2018
2032
}
2019
2033
2020
2034
2021
2035
//////////////////////////////////////////////////////////////
2022
2036
// Inner Class Definition for CheckPointer (Observable) //
2023
2037
//////////////////////////////////////////////////////////////
2038
+
2024
2039
/**
2025
2040
* <p>
2026
- * Implementation of the CheckPointer interface which serves to checkpoint
2041
+ * Implementation of the CheckPointOp interface which serves to checkpoint
2027
2042
* and register a listener at the same time. The {@link rx.Observer} will be
2028
2043
* notified with the byte array of the {@link Network} being serialized.
2029
2044
* </p><p>
@@ -2032,18 +2047,18 @@ CheckPointer<byte[]> checkPointer() {
2032
2047
* be executed.
2033
2048
* </p>
2034
2049
*
2035
- * @param <T> {@link rx.Observer}
2050
+ * @param <T> {@link rx.Observer}'s return type
2036
2051
*/
2037
- static class CheckPointerImpl <T > extends Observable <T > implements CheckPointer <T > {
2038
- private CheckPointerImpl (Layer <?> l ) {
2052
+ static class CheckPointOperator <T > extends Observable <T > implements CheckPointOp <T > {
2053
+ private CheckPointOperator (Layer <?> l ) {
2039
2054
this (new Observable .OnSubscribe <T >() {
2040
- @ SuppressWarnings ("unchecked" )
2041
- @ Override public void call (Subscriber <? super T > t ) {
2055
+ @ SuppressWarnings ({ "unchecked" } )
2056
+ @ Override public void call (Subscriber <? super T > r ) {
2042
2057
if (l .LAYER_THREAD != null ) {
2043
2058
// The layer thread automatically tests for the list of observers to
2044
2059
// contain > 0 elements, which indicates a check point operation should
2045
2060
// be executed.
2046
- l .checkPointObservers .add ((Observer <byte []>)t );
2061
+ l .checkPointOpObservers .add ((Observer <byte []>)r );
2047
2062
}else {
2048
2063
l .doCheckPoint ();
2049
2064
}
@@ -2052,10 +2067,10 @@ private CheckPointerImpl(Layer<?> l) {
2052
2067
}
2053
2068
2054
2069
/**
2055
- * Constructs this {@code CheckPointerImpl }
2070
+ * Constructs this {@code CheckPointOperator }
2056
2071
* @param f a subscriber function
2057
2072
*/
2058
- protected CheckPointerImpl (rx .Observable .OnSubscribe <T > f ) {
2073
+ protected CheckPointOperator (rx .Observable .OnSubscribe <T > f ) {
2059
2074
super (f );
2060
2075
}
2061
2076
0 commit comments