All Downloads are FREE. Search and download functionalities are using the official Maven repository.

swim.runtime.lane.JoinMapLaneView Maven / Gradle / Ivy

There is a newer version: 3.10.0
Show newest version
// Copyright 2015-2019 SWIM.AI inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package swim.runtime.lane;

import java.util.AbstractMap;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import swim.api.Link;
import swim.api.SwimContext;
import swim.api.agent.AgentContext;
import swim.api.data.MapData;
import swim.api.downlink.MapDownlink;
import swim.api.http.function.DecodeRequestHttp;
import swim.api.http.function.DidRequestHttp;
import swim.api.http.function.DidRespondHttp;
import swim.api.http.function.DoRespondHttp;
import swim.api.http.function.WillRequestHttp;
import swim.api.http.function.WillRespondHttp;
import swim.api.lane.JoinMapLane;
import swim.api.lane.Lane;
import swim.api.lane.function.DidCommand;
import swim.api.lane.function.DidDownlinkMap;
import swim.api.lane.function.DidEnter;
import swim.api.lane.function.DidLeave;
import swim.api.lane.function.DidUplink;
import swim.api.lane.function.WillCommand;
import swim.api.lane.function.WillDownlinkMap;
import swim.api.lane.function.WillEnter;
import swim.api.lane.function.WillLeave;
import swim.api.lane.function.WillUplink;
import swim.concurrent.Conts;
import swim.observable.function.DidClear;
import swim.observable.function.DidRemoveKey;
import swim.observable.function.DidUpdateKey;
import swim.observable.function.WillClear;
import swim.observable.function.WillRemoveKey;
import swim.observable.function.WillUpdateKey;
import swim.runtime.LaneContext;
import swim.structure.Form;
import swim.structure.Value;
import swim.uri.Uri;

public class JoinMapLaneView extends LaneView implements JoinMapLane {
  protected final AgentContext agentContext;
  protected Form linkForm;
  protected Form keyForm;
  protected Form valueForm;

  protected int flags;
  protected JoinMapLaneModel laneBinding;
  protected MapData dataView;

  JoinMapLaneView(AgentContext agentContext, Form linkForm, Form keyForm,
                  Form valueForm, int flags, Object observers) {
    super(observers);
    this.agentContext = agentContext;
    this.linkForm = linkForm;
    this.keyForm = keyForm;
    this.valueForm = valueForm;
    this.flags = flags;
  }

  public JoinMapLaneView(AgentContext agentContext, Form linkForm,
                         Form keyForm, Form valueForm) {
    this(agentContext, linkForm, keyForm, valueForm, RESIDENT, null);
  }

  @Override
  public AgentContext agentContext() {
    return this.agentContext;
  }

  @Override
  public JoinMapLaneModel getLaneBinding() {
    return this.laneBinding;
  }

  void setLaneBinding(JoinMapLaneModel laneBinding) {
    this.laneBinding = laneBinding;
    this.dataView = laneBinding.data.keyForm(this.keyForm).valueForm(this.valueForm);
  }

  @Override
  public JoinMapLaneModel createLaneBinding() {
    return new JoinMapLaneModel(this.flags);
  }

  @Override
  public final Form linkForm() {
    return this.linkForm;
  }

  @Override
  public  JoinMapLaneView linkForm(Form linkForm) {
    return new JoinMapLaneView(this.agentContext, linkForm, this.keyForm, this.valueForm,
                                         this.flags, typesafeObservers(this.observers));
  }

  @Override
  public  JoinMapLaneView linkClass(Class linkClass) {
    return linkForm(Form.forClass(linkClass));
  }

  public void setLinkForm(Form linkForm) {
    this.linkForm = linkForm;
  }

  @Override
  public final Form keyForm() {
    return keyForm;
  }

  @Override
  public  JoinMapLaneView keyForm(Form keyForm) {
    return new JoinMapLaneView(this.agentContext, this.linkForm, keyForm, this.valueForm,
                                         this.flags, typesafeObservers(this.observers));
  }

  @Override
  public  JoinMapLaneView keyClass(Class keyClass) {
    return keyForm(Form.forClass(keyClass));
  }

  public void setKeyForm(Form keyForm) {
    this.keyForm = keyForm;
  }

  @Override
  public final Form valueForm() {
    return valueForm;
  }

  @Override
  public  JoinMapLaneView valueForm(Form valueForm) {
    return new JoinMapLaneView(this.agentContext, this.linkForm, this.keyForm, valueForm,
                                         this.flags, typesafeObservers(this.observers));
  }

  @Override
  public  JoinMapLaneView valueClass(Class valueClass) {
    return valueForm(Form.forClass(valueClass));
  }

  public void setValueForm(Form valueForm) {
    this.valueForm = valueForm;
  }

  protected Object typesafeObservers(Object observers) {
    // TODO: filter out WillDownlinkMap, DidDownlinkMap, WillUpdateKey, DidUpdateKey,
    //       WillRemoveKey, DidRemoveKey, WillClear, DidClear
    return observers;
  }

  public final boolean isResident() {
    return (this.flags & RESIDENT) != 0;
  }

  @Override
  public JoinMapLaneView isResident(boolean isResident) {
    if (isResident) {
      this.flags |= RESIDENT;
    } else {
      this.flags &= ~RESIDENT;
    }
    final JoinMapLaneModel laneBinding = this.laneBinding;
    if (laneBinding != null) {
      laneBinding.isResident(isResident);
    }
    return this;
  }

  void didSetResident(boolean isResident) {
    if (isResident) {
      this.flags |= RESIDENT;
    } else {
      this.flags &= ~RESIDENT;
    }
  }

  public final boolean isTransient() {
    return (this.flags & TRANSIENT) != 0;
  }

  @Override
  public JoinMapLaneView isTransient(boolean isTransient) {
    if (isTransient) {
      this.flags |= TRANSIENT;
    } else {
      this.flags &= ~TRANSIENT;
    }
    final JoinMapLaneModel laneBinding = this.laneBinding;
    if (laneBinding != null) {
      laneBinding.isTransient(isTransient);
    }
    return this;
  }

  void didSetTransient(boolean isTransient) {
    if (isTransient) {
      this.flags |= TRANSIENT;
    } else {
      this.flags &= ~TRANSIENT;
    }
  }

  @Override
  public final boolean isSigned() {
    return (this.flags & SIGNED) != 0;
  }

  @Override
  public JoinMapLaneView isSigned(boolean isSigned) {
    didSetSigned(isSigned);

    // note: marked final given access of concurrently accessed volatile objects
    final JoinMapLaneModel laneBinding = this.laneBinding;

    if (laneBinding != null) {
      laneBinding.isSigned(isSigned);
    }

    return this;
  }

  void didSetSigned(boolean isSigned) {
    if (isSigned) {
      this.flags |= SIGNED;
    } else {
      this.flags &= ~SIGNED;
    }
  }

  @Override
  public void close() {
    this.laneBinding.closeLaneView(this);
  }

  @SuppressWarnings("unchecked")
  @Override
  public JoinMapLaneView observe(Object observer) {
    return (JoinMapLaneView) super.observe(observer);
  }

  @SuppressWarnings("unchecked")
  @Override
  public JoinMapLaneView unobserve(Object observer) {
    return (JoinMapLaneView) super.unobserve(observer);
  }

  @Override
  public JoinMapLaneView willDownlink(WillDownlinkMap willDownlink) {
    return observe(willDownlink);
  }

  @Override
  public JoinMapLaneView didDownlink(DidDownlinkMap didDownlink) {
    return observe(didDownlink);
  }

  @Override
  public JoinMapLaneView willUpdate(WillUpdateKey willUpdate) {
    return observe(willUpdate);
  }

  @Override
  public JoinMapLaneView didUpdate(DidUpdateKey didUpdate) {
    return observe(didUpdate);
  }

  @Override
  public JoinMapLaneView willRemove(WillRemoveKey willRemove) {
    return observe(willRemove);
  }

  @Override
  public JoinMapLaneView didRemove(DidRemoveKey didRemove) {
    return observe(didRemove);
  }

  @Override
  public JoinMapLaneView willClear(WillClear willClear) {
    return observe(willClear);
  }

  @Override
  public JoinMapLaneView didClear(DidClear didClear) {
    return observe(didClear);
  }

  @Override
  public JoinMapLaneView willCommand(WillCommand willCommand) {
    return observe(willCommand);
  }

  @Override
  public JoinMapLaneView didCommand(DidCommand didCommand) {
    return observe(didCommand);
  }

  @Override
  public JoinMapLaneView willUplink(WillUplink willUplink) {
    return observe(willUplink);
  }

  @Override
  public JoinMapLaneView didUplink(DidUplink didUplink) {
    return observe(didUplink);
  }

  @Override
  public JoinMapLaneView willEnter(WillEnter willEnter) {
    return observe(willEnter);
  }

  @Override
  public JoinMapLaneView didEnter(DidEnter didEnter) {
    return observe(didEnter);
  }

  @Override
  public JoinMapLaneView willLeave(WillLeave willLeave) {
    return observe(willLeave);
  }

  @Override
  public JoinMapLaneView didLeave(DidLeave didLeave) {
    return observe(didLeave);
  }

  @Override
  public JoinMapLaneView decodeRequest(DecodeRequestHttp decodeRequest) {
    return observe(decodeRequest);
  }

  @Override
  public JoinMapLaneView willRequest(WillRequestHttp willRequest) {
    return observe(willRequest);
  }

  @Override
  public JoinMapLaneView didRequest(DidRequestHttp didRequest) {
    return observe(didRequest);
  }

  @Override
  public JoinMapLaneView doRespond(DoRespondHttp doRespond) {
    return observe(doRespond);
  }

  @Override
  public JoinMapLaneView willRespond(WillRespondHttp willRespond) {
    return observe(willRespond);
  }

  @Override
  public JoinMapLaneView didRespond(DidRespondHttp didRespond) {
    return observe(didRespond);
  }

  @SuppressWarnings("unchecked")
  protected Map.Entry dispatchWillUpdate(Link link, K key, V newValue, boolean preemptive) {
    final Lane oldLane = SwimContext.getLane();
    final Link oldLink = SwimContext.getLink();
    try {
      SwimContext.setLane(this);
      SwimContext.setLink(link);
      final Object observers = this.observers;
      boolean complete = true;
      if (observers instanceof WillUpdateKey) {
        if (((WillUpdateKey) observers).isPreemptive() == preemptive) {
          try {
            newValue = ((WillUpdateKey) observers).willUpdate(key, newValue);
          } catch (Throwable error) {
            if (Conts.isNonFatal(error)) {
              laneDidFail(error);
            } else {
              throw error;
            }
          }
        } else if (preemptive) {
          complete = false;
        }
      } else if (observers instanceof Object[]) {
        final Object[] array = (Object[]) observers;
        for (int i = 0, n = array.length; i < n; i += 1) {
          final Object observer = array[i];
          if (observer instanceof WillUpdateKey) {
            if (((WillUpdateKey) observer).isPreemptive() == preemptive) {
              try {
                newValue = ((WillUpdateKey) observer).willUpdate(key, newValue);
              } catch (Throwable error) {
                if (Conts.isNonFatal(error)) {
                  laneDidFail(error);
                } else {
                  throw error;
                }
              }
            } else if (preemptive) {
              complete = false;
            }
          }
        }
      }
      return new AbstractMap.SimpleImmutableEntry(complete, newValue);
    } finally {
      SwimContext.setLink(oldLink);
      SwimContext.setLane(oldLane);
    }
  }

  @SuppressWarnings("unchecked")
  protected boolean dispatchDidUpdate(Link link, K key, V newValue, V oldValue, boolean preemptive) {
    final Lane oldLane = SwimContext.getLane();
    final Link oldLink = SwimContext.getLink();
    try {
      SwimContext.setLane(this);
      SwimContext.setLink(link);
      final Object observers = this.observers;
      boolean complete = true;
      if (observers instanceof DidUpdateKey) {
        if (((DidUpdateKey) observers).isPreemptive() == preemptive) {
          try {
            ((DidUpdateKey) observers).didUpdate(key, newValue, oldValue);
          } catch (Throwable error) {
            if (Conts.isNonFatal(error)) {
              laneDidFail(error);
            } else {
              throw error;
            }
          }
        } else if (preemptive) {
          complete = false;
        }
      } else if (observers instanceof Object[]) {
        final Object[] array = (Object[]) observers;
        for (int i = 0, n = array.length; i < n; i += 1) {
          final Object observer = array[i];
          if (observer instanceof DidUpdateKey) {
            if (((DidUpdateKey) observer).isPreemptive() == preemptive) {
              try {
                ((DidUpdateKey) observer).didUpdate(key, newValue, oldValue);
              } catch (Throwable error) {
                if (Conts.isNonFatal(error)) {
                  laneDidFail(error);
                } else {
                  throw error;
                }
              }
            } else if (preemptive) {
              complete = false;
            }
          }
        }
      }
      return complete;
    } finally {
      SwimContext.setLink(oldLink);
      SwimContext.setLane(oldLane);
    }
  }

  @SuppressWarnings("unchecked")
  protected boolean dispatchWillRemove(Link link, K key, boolean preemptive) {
    final Lane oldLane = SwimContext.getLane();
    final Link oldLink = SwimContext.getLink();
    try {
      SwimContext.setLane(this);
      SwimContext.setLink(link);
      final Object observers = this.observers;
      boolean complete = true;
      if (observers instanceof WillRemoveKey) {
        if (((WillRemoveKey) observers).isPreemptive() == preemptive) {
          try {
            ((WillRemoveKey) observers).willRemove(key);
          } catch (Throwable error) {
            if (Conts.isNonFatal(error)) {
              laneDidFail(error);
            } else {
              throw error;
            }
          }
        } else if (preemptive) {
          complete = false;
        }
      } else if (observers instanceof Object[]) {
        final Object[] array = (Object[]) observers;
        for (int i = 0, n = array.length; i < n; i += 1) {
          final Object observer = array[i];
          if (observer instanceof WillRemoveKey) {
            if (((WillRemoveKey) observer).isPreemptive() == preemptive) {
              try {
                ((WillRemoveKey) observer).willRemove(key);
              } catch (Throwable error) {
                if (Conts.isNonFatal(error)) {
                  laneDidFail(error);
                } else {
                  throw error;
                }
              }
            } else if (preemptive) {
              complete = false;
            }
          }
        }
      }
      return complete;
    } finally {
      SwimContext.setLink(oldLink);
      SwimContext.setLane(oldLane);
    }
  }

  @SuppressWarnings("unchecked")
  protected boolean dispatchDidRemove(Link link, K key, V oldValue, boolean preemptive) {
    final Lane oldLane = SwimContext.getLane();
    final Link oldLink = SwimContext.getLink();
    try {
      SwimContext.setLane(this);
      SwimContext.setLink(link);
      final Object observers = this.observers;
      boolean complete = true;
      if (observers instanceof DidRemoveKey) {
        if (((DidRemoveKey) observers).isPreemptive() == preemptive) {
          try {
            ((DidRemoveKey) observers).didRemove(key, oldValue);
          } catch (Throwable error) {
            if (Conts.isNonFatal(error)) {
              laneDidFail(error);
            } else {
              throw error;
            }
          }
        } else if (preemptive) {
          complete = false;
        }
      } else if (observers instanceof Object[]) {
        final Object[] array = (Object[]) observers;
        for (int i = 0, n = array.length; i < n; i += 1) {
          final Object observer = array[i];
          if (observer instanceof DidRemoveKey) {
            if (((DidRemoveKey) observer).isPreemptive() == preemptive) {
              try {
                ((DidRemoveKey) observer).didRemove(key, oldValue);
              } catch (Throwable error) {
                if (Conts.isNonFatal(error)) {
                  laneDidFail(error);
                } else {
                  throw error;
                }
              }
            } else if (preemptive) {
              complete = false;
            }
          }
        }
      }
      return complete;
    } finally {
      SwimContext.setLink(oldLink);
      SwimContext.setLane(oldLane);
    }
  }

  protected boolean dispatchWillClear(Link link, boolean preemptive) {
    final Lane oldLane = SwimContext.getLane();
    final Link oldLink = SwimContext.getLink();
    try {
      SwimContext.setLane(this);
      SwimContext.setLink(link);
      final Object observers = this.observers;
      boolean complete = true;
      if (observers instanceof WillClear) {
        if (((WillClear) observers).isPreemptive() == preemptive) {
          try {
            ((WillClear) observers).willClear();
          } catch (Throwable error) {
            if (Conts.isNonFatal(error)) {
              laneDidFail(error);
            } else {
              throw error;
            }
          }
        } else if (preemptive) {
          complete = false;
        }
      } else if (observers instanceof Object[]) {
        final Object[] array = (Object[]) observers;
        for (int i = 0, n = array.length; i < n; i += 1) {
          final Object observer = array[i];
          if (observer instanceof WillClear) {
            if (((WillClear) observer).isPreemptive() == preemptive) {
              try {
                ((WillClear) observer).willClear();
              } catch (Throwable error) {
                if (Conts.isNonFatal(error)) {
                  laneDidFail(error);
                } else {
                  throw error;
                }
              }
            } else if (preemptive) {
              complete = false;
            }
          }
        }
      }
      return complete;
    } finally {
      SwimContext.setLink(oldLink);
      SwimContext.setLane(oldLane);
    }
  }

  protected boolean dispatchDidClear(Link link, boolean preemptive) {
    final Lane oldLane = SwimContext.getLane();
    final Link oldLink = SwimContext.getLink();
    try {
      SwimContext.setLane(this);
      SwimContext.setLink(link);
      final Object observers = this.observers;
      boolean complete = true;
      if (observers instanceof DidClear) {
        if (((DidClear) observers).isPreemptive() == preemptive) {
          try {
            ((DidClear) observers).didClear();
          } catch (Throwable error) {
            if (Conts.isNonFatal(error)) {
              laneDidFail(error);
            } else {
              throw error;
            }
          }
        } else if (preemptive) {
          complete = false;
        }
      } else if (observers instanceof Object[]) {
        final Object[] array = (Object[]) observers;
        for (int i = 0, n = array.length; i < n; i += 1) {
          final Object observer = array[i];
          if (observer instanceof DidClear) {
            if (((DidClear) observer).isPreemptive() == preemptive) {
              try {
                ((DidClear) observer).didClear();
              } catch (Throwable error) {
                if (Conts.isNonFatal(error)) {
                  laneDidFail(error);
                } else {
                  throw error;
                }
              }
            } else if (preemptive) {
              complete = false;
            }
          }
        }
      }
      return complete;
    } finally {
      SwimContext.setLink(oldLink);
      SwimContext.setLane(oldLane);
    }
  }

  @SuppressWarnings("unchecked")
  protected Map.Entry> dispatchWillDownlink(L key, MapDownlink downlink, boolean preemptive) {
    final Lane oldLane = SwimContext.getLane();
    try {
      SwimContext.setLane(this);
      final Object observers = this.observers;
      boolean complete = true;
      if (observers instanceof WillDownlinkMap) {
        if (((WillDownlinkMap) observers).isPreemptive() == preemptive) {
          try {
            downlink = ((WillDownlinkMap) observers).willDownlink(key, downlink);
          } catch (Throwable error) {
            if (Conts.isNonFatal(error)) {
              laneDidFail(error);
            } else {
              throw error;
            }
          }
        } else if (preemptive) {
          complete = false;
        }
      } else if (observers instanceof Object[]) {
        final Object[] array = (Object[]) observers;
        for (int i = 0, n = array.length; i < n; i += 1) {
          final Object observer = array[i];
          if (observer instanceof WillDownlinkMap) {
            if (((WillDownlinkMap) observer).isPreemptive() == preemptive) {
              try {
                downlink = ((WillDownlinkMap) observer).willDownlink(key, downlink);
              } catch (Throwable error) {
                if (Conts.isNonFatal(error)) {
                  laneDidFail(error);
                } else {
                  throw error;
                }
              }
            } else if (preemptive) {
              complete = false;
            }
          }
        }
      }
      return new AbstractMap.SimpleImmutableEntry>(complete, downlink);
    } finally {
      SwimContext.setLane(oldLane);
    }
  }

  @SuppressWarnings("unchecked")
  protected boolean dispatchDidDownlink(L key, MapDownlink downlink, boolean preemptive) {
    final Lane oldLane = SwimContext.getLane();
    try {
      SwimContext.setLane(this);
      final Object observers = this.observers;
      boolean complete = true;
      if (observers instanceof DidDownlinkMap) {
        if (((DidDownlinkMap) observers).isPreemptive() == preemptive) {
          try {
            ((DidDownlinkMap) observers).didDownlink(key, downlink);
          } catch (Throwable error) {
            if (Conts.isNonFatal(error)) {
              laneDidFail(error);
            } else {
              throw error;
            }
          }
        } else if (preemptive) {
          complete = false;
        }
      } else if (observers instanceof Object[]) {
        final Object[] array = (Object[]) observers;
        for (int i = 0, n = array.length; i < n; i += 1) {
          final Object observer = array[i];
          if (observer instanceof DidDownlinkMap) {
            if (((DidDownlinkMap) observer).isPreemptive() == preemptive) {
              try {
                ((DidDownlinkMap) observer).didDownlink(key, downlink);
              } catch (Throwable error) {
                if (Conts.isNonFatal(error)) {
                  laneDidFail(error);
                } else {
                  throw error;
                }
              }
            } else if (preemptive) {
              complete = false;
            }
          }
        }
      }
      return complete;
    } finally {
      SwimContext.setLane(oldLane);
    }
  }

  public MapDownlink laneWillDownlink(L key, MapDownlink downlink) {
    return downlink;
  }

  public void laneDidDownlink(K key, MapDownlink downlink) {
  }

  public V laneWillUpdate(K key, V newValue) {
    return newValue;
  }

  public void laneDidUpdate(K key, V newValue, V oldValue) {
  }

  public void laneWillRemove(K key) {
  }

  public void laneDidRemove(K key, V oldValue) {
  }

  public void laneWillClear() {
  }

  public void laneDidClear() {
  }

  @Override
  public MapDownlink downlink(L key) {
    final LaneContext laneContext = this.laneBinding.laneContext;
    return new JoinMapLaneDownlink(laneContext, laneContext.stage(),
        this.laneBinding, this.linkForm.mold(key).toValue(), this.laneBinding.meshUri(), Uri.empty(),
        Uri.empty(), Uri.empty(), 0.0f, 0.0f, Value.absent(), this.keyForm, this.valueForm);
  }

  @Override
  public boolean isEmpty() {
    return this.dataView.isEmpty();
  }

  @Override
  public int size() {
    return this.dataView.size();
  }

  @Override
  public boolean containsKey(Object key) {
    return this.dataView.containsKey(key);
  }

  @Override
  public boolean containsValue(Object value) {
    return this.dataView.containsValue(value);
  }

  @Override
  public V get(Object key) {
    return this.dataView.get(key);
  }

  @SuppressWarnings("unchecked")
  @Override
  public MapDownlink getDownlink(Object key) {
    return this.laneBinding.getDownlink(this.linkForm.mold((L) key));
  }

  @Override
  public V put(K key, V value) {
    return this.laneBinding.put(this, key, value);
  }

  @Override
  public void putAll(Map map) {
    for (Map.Entry entry : map.entrySet()) {
      this.laneBinding.put(this, entry.getKey(), entry.getValue());
    }
  }

  @SuppressWarnings("unchecked")
  @Override
  public V remove(Object key) {
    final Class keyType = this.keyForm.type();
    if (keyType == null || keyType.isInstance(key)) {
      return this.laneBinding.remove(this, (K) key);
    }
    return this.valueForm.unit();
  }

  @Override
  public void clear() {
    this.laneBinding.clear(this);
  }

  @Override
  public Set> entrySet() {
    return this.dataView.entrySet();
  }

  @Override
  public Set keySet() {
    return this.dataView.keySet();
  }

  @Override
  public Collection values() {
    return this.dataView.values();
  }

  @Override
  public Iterator> iterator() {
    return this.dataView.iterator();
  }

  @Override
  public Iterator keyIterator() {
    return this.dataView.keyIterator();
  }

  @Override
  public Iterator valueIterator() {
    return this.dataView.valueIterator();
  }

  @SuppressWarnings("unchecked")
  @Override
  public Iterator>> downlinkIterator() {
    return (Iterator>>) (Iterator) this.laneBinding.downlinks.iterator();
  }

  static final int RESIDENT = 1 << 0;
  static final int TRANSIENT = 1 << 1;
  static final int SIGNED = 1 << 2;
}