Class UpdateRequestBuilder


  • public class UpdateRequestBuilder
    extends java.lang.Object
    Builder for UpdateRequest objects.

    Usage example (for a circular machine):

     UpdateRequestBuilder builder = new UpdateRequestBuilder(true);
     UpdateRequest request = builder.setOptic(YOUR_OPTIC)
                                  .setElements(YOUR_ELEMENTS)
                                  .setActiveMonitors(H, YOUR_H_MONITORS)
                                  .setActiveMonitors(V, YOUR_V_MONITORS)
                                  .build();
     
    and later on, when only your active monitors have changed:
     UpdateRequest request = builder.setActiveMonitors(H, YOUR_H_MONITORS)
                                  .setActiveMonitors(V, YOUR_V_MONITORS)
                                  .build();
     
    and so forth and so on...

    This Builder can be reused for multiple update calls and is thread save, as both set-methods and the build method are synchronized. Therefore it is possible to set optic and elements in one thread and use the builder in another one, where the actual update is performed.

    • Constructor Detail

      • UpdateRequestBuilder

        public UpdateRequestBuilder​(boolean isCirularMachine)
        The constructor of a update request builder.
        Parameters:
        isCirularMachine - pass true if this update request builder is for a circular machine/synchrotron
    • Method Detail

      • setOptic

        public UpdateRequestBuilder setOptic​(Optic optic)
        Set the optic to use in the update request.
        Parameters:
        optic - the optic to use
        Returns:
        the builder
        Throws:
        java.lang.IllegalArgumentException - if null is passed
      • setElements

        public UpdateRequestBuilder setElements​(java.util.List<Element> elements)
        Set the elements defining the machine.
        Parameters:
        elements - the list of elements
        Returns:
        the builder
        Throws:
        java.lang.IllegalArgumentException - in case the provided elements are null or an empty is passed
      • setActiveMonitors

        public UpdateRequestBuilder setActiveMonitors​(JMadPlane plane,
                                                      java.util.Set<Element> monitors)
        Set the active monitors for a given plane in the builder.
        Parameters:
        plane - the JMadPlane to set the active monitors for
        monitors - the set of monitors to set active
        Returns:
        the builder
        Throws:
        java.lang.IllegalArgumentException - if the provided set of monitor elements is null, or does not contain at least two monitors
      • fullUpdate

        public UpdateRequestBuilder fullUpdate​(java.util.List<Element> elements,
                                               java.util.Map<JMadPlane,​java.util.Set<Element>> monitors,
                                               Optic optic)
        Create a full update request in case the machine elements changed.
        Parameters:
        elements - the list of elements to use
        monitors - the list of monitors to use
        optic - the optic to use
        Returns:
        the builder
        Throws:
        java.lang.IllegalArgumentException - if one of the arguments is illegal
      • buildRequest

        public UpdateRequest buildRequest()
        Returns:
        the actual request based on the current state of the builder.
        Throws:
        java.lang.IllegalStateException - in case one of the constraints is not fulfilled