Package jadex.bridge

Class SFuture


  • public class SFuture
    extends java.lang.Object
    Helper class for future aspects.
    • Constructor Detail

      • SFuture

        public SFuture()
    • Method Detail

      • streamToFuture

        public static <T> IntermediateFuture<T> streamToFuture​(IInternalAccess agent,
                                                               java.util.stream.Stream<T> results)
        Create an intermediate future for a stream. The results are pulled from the stream using the agent thread i.e. the agent will be blocked when waiting for stream results. Safe to use (but somewhat useless) for finished streams. Also safe to use for streams, created with IntermediateFuture.asStream(). Not safe to use for other kinds of infinite streams!
      • avoidCallTimeouts

        public static void avoidCallTimeouts​(Future<?> ret,
                                             IInternalAccess ia)
        Automatically update the timer of a long running service call future. Ensures that the caller does not timeout even if no result value is set in that time span. The call periodically sends alive calls to the caller.
        Parameters:
        ret - The future that is returned by the service call.
        ia - The component handling the service call (on that component the periodic updates are scheduled).
      • avoidCallTimeouts

        public static void avoidCallTimeouts​(Future<?> ret,
                                             IInternalAccess ia,
                                             boolean realtime)
        Automatically update the timer of a long running service call future. Ensures that the caller does not timeout even if no result value is set in that time span. The call periodically sends alive calls to the caller.
        Parameters:
        ret - The future that is returned by the service call.
        ia - The component handling the service call (on that component the periodic updates are scheduled).
        realtime - true, for real time timeouts (simulation clock based timeouts otherwise).
      • avoidCallTimeouts

        public static void avoidCallTimeouts​(Future<?> ret,
                                             IExternalAccess ea)
        Automatically update the timer of a long running service call future. Ensures that the caller does not timeout even if no result value is set in that timespan. The call periodically sends alive calls to the caller.
        Parameters:
        ret - The future that is returned by the service call.
        ea - The component handling the service call (on that component the periodic updates are scheduled).
      • avoidCallTimeouts

        public static void avoidCallTimeouts​(Future<?> ret,
                                             IInternalAccess ia,
                                             long to,
                                             boolean realtime)
        Automatically update the timer of a long running service call future. Ensures that the caller does not timeout even if no result value is set in that timespan. The call periodically sends alive calls to the caller.
        Parameters:
        ret - The future that is returned by the service call.
        ia - The component handling the service call (on that component the periodic updates are scheduled).
        to - The timeout.
      • avoidCallTimeouts

        public static void avoidCallTimeouts​(Future<?> ret,
                                             IExternalAccess ea,
                                             long to,
                                             boolean realtime)
        Automatically update the timer of a long running service call future. Ensures that the caller does not timeout even if no result value is set in that timespan. The call periodically sends alive calls to the caller.
        Parameters:
        ret - The future that is returned by the service call.
        ea - The component handling the service call (on that component the periodic updates are scheduled).
        to - The timeout.
      • avoidCallTimeouts

        public static void avoidCallTimeouts​(Future<?> ret,
                                             IInternalAccess ia,
                                             long to,
                                             double factor,
                                             boolean realtime)
        Automatically update the timer of a long running service call future. Ensures that the caller does not timeout even if no result value is set in that timespan. The call periodically sends alive calls to the caller.
        Parameters:
        ret - The future that is returned by the service call.
        ia - The component handling the service call (on that component the periodic updates are scheduled).
        to - The timeout.
        factor - (default 0.8) Used to update the timer when factor*to has elapsed.
      • avoidCallTimeouts

        public static void avoidCallTimeouts​(Future<?> ret,
                                             IExternalAccess ea,
                                             long to,
                                             double factor,
                                             boolean realtime)
        Automatically update the timer of a long running service call future. Ensures that the caller does not timeout even if no result value is set in that timespan. The call periodically sends alive calls to the caller.
        Parameters:
        ret - The future that is returned by the service call.
        ea - The component handling the service call (on that component the periodic updates are scheduled).
        to - The timeout.
        factor - (default 0.8) Used to update the timer when factor*to has elapsed.
      • getNoTimeoutFuture

        public static <T> Future<?> getNoTimeoutFuture​(IInternalAccess ia)
        Convenience method for creating a future (possibly with timeout avoidance).
        Parameters:
        timeouts - (default is true) False, if no timeouts should be generated when service call timeout has elapsed.
        ea - The external access.
      • getNoTimeoutFuture

        public static <T> Future<?> getNoTimeoutFuture​(java.lang.Class<T> type,
                                                       IInternalAccess ia)
        Convenience method for creating a future (possibly with timeout avoidance).
        Parameters:
        timeouts - (default is true) False, if no timeouts should be generated when service call timeout has elapsed.
        ia - The internal access.
      • getNoTimeoutFuture

        public static <T> Future<?> getNoTimeoutFuture​(java.lang.Class<T> type,
                                                       IInternalAccess ia,
                                                       boolean realtime)
        Convenience method for creating a future with timeout avoidance.
        Parameters:
        type - The future type (e.g. IntermediateFuture.class).
        ia - The internal access.
        realtime - true, for real time timeouts (simulation clock based timeouts otherwise).
      • getNoTimeoutFuture

        public static <T> Future<?> getNoTimeoutFuture​(java.lang.Class<T> type,
                                                       IExternalAccess ea)
        Convenience method for creating a future (possibly with timeout avoidance).
        Parameters:
        timeouts - (default is true) False, if no timeouts should be generated when service call timeout has elapsed.
        ea - The external access.
      • getFuture

        public static <T> Future<?> getFuture​(boolean timeouts,
                                              IInternalAccess ia)
        Convenience method for creating a future (possibly with timeout avoidance).
        Parameters:
        timeouts - (default is true) False, if no timeouts should be generated when service call timeout has elapsed.
        ia - The external access.
      • getFuture

        public static <T> Future<?> getFuture​(java.lang.Class<T> type,
                                              boolean timeouts,
                                              IInternalAccess ia)
        Convenience method for creating a future (possibly with timeout avoidance).
        Parameters:
        type - The future implementation type.
        timeouts - (default is true) False, if no timeouts should be generated when service call timeout has elapsed.
        ia - The external access.
      • getFuture

        public static <T> Future<?> getFuture​(java.lang.Class<T> type,
                                              boolean timeouts,
                                              IExternalAccess ea)
        Convenience method for creating a future (possibly with timeout avoidance).
        Parameters:
        type - The future implementation type.
        timeouts - (default is true) False, if no timeouts should be generated when service call timeout has elapsed.
        ea - The external access.
      • getFuture

        public static Future<?> getFuture​(java.lang.Class<?> clazz)
        Get the matching future object to a future (interface) type.
      • getFirstResultAndTerminate

        public static <T> T getFirstResultAndTerminate​(ITerminableIntermediateFuture<T> fut)
        Blocking wait for first result. Future is terminated after first result is received. Defaults to realtime timeout (hack?)
        Parameters:
        fut - The future.
        Returns:
        The first result.