Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

19장 message와 flow

10장에서는 port와 interface로 part를 연결했습니다. 그 연결을 통해 누가 누구에게 무엇을 언제 전달하는지는 아직 적지 않았습니다. 지상 통제소가 드론에 명령을 보내는 일, 드론이 상태를 보고하는 일, 배터리의 전력이 비행 제어기에 공급되는 일은 모두 한쪽에서 다른 쪽으로 무언가를 전달한다는 공통점이 있습니다. SysML에서는 이런 전달을 transfer라고 하며 flow로 모델링합니다. 이 장에서는 전달을 세 가지 수준으로 표현하는 방법과 action이 직접 보내고 받는 동작을 나타내는 send와 accept를 설명합니다.

transfer를 적는 세 가지 수준

flow usage는 전달 과정을 얼마나 자세히 나타내느냐에 따라 세 가지로 나뉩니다.

종류키워드정하는 것
messagemessage누구에게서 누구에게 무엇이 간다는 것만 정합니다.
flowflow보내는 쪽의 어느 출력에서 받는 쪽의 어느 입력으로 가는지까지 정합니다.
succession flowsuccession flowflow에 순서를 더합니다. 보내는 쪽이 끝난 뒤에 옮기고, 다 옮긴 뒤에 받는 쪽이 시작합니다.

옮겨 가는 대상을 payload라고 합니다. payload는 item, part, attribute의 value 가운데 무엇이든 될 수 있습니다.

flow: 출력에서 입력으로

flow는 from 뒤에 보내는 쪽의 출력 feature를, to 뒤에 받는 쪽의 입력 feature를 적습니다.

part def Drone {
    part battery : Battery;
    part flightController : FlightController;

    flow of ElectricPower
        from battery.powerOut.power to flightController.powerIn.power;
}

battery.powerOut.power는 배터리의 port powerOut에 있는 out feature이고, flightController.powerIn.power는 비행 제어기의 port powerIn에 있는 in feature입니다. of 뒤에는 payload의 type을 적습니다. 적지 않으면 양쪽 feature의 type에 맞는 것은 무엇이든 옮겨 갈 수 있고, 선언을 flow battery.powerOut.power to flightController.powerIn.power;로 줄일 수 있습니다.

flow가 연결하는 대상은 출력 feature와 입력 feature 자체가 아니라 각 feature를 가진 쪽입니다. 각 대상은 feature chain에서 마지막 feature를 뺀 부분에 해당합니다. 위 flow는 battery.powerOut과 flightController.powerIn을 잇습니다.

action 사이에도 flow를 씁니다. 16장에서는 in location = cruise.arrival;로 두 parameter를 묶었습니다. binding은 두 값이 언제나 같다는 조건이고, flow는 한쪽에서 나온 것이 다른 쪽으로 옮겨 가는 일입니다.

표기뜻맞는 경우
in location = cruise.arrival;두 parameter의 value가 언제나 같습니다.값을 넘겨주기만 할 때
flow cruise.arrival to dropOff.location;cruise의 출력이 dropOff의 입력으로 전달됩니다. 두 action이 수행되는 동안 전달이 계속될 수 있습니다.전달 자체에 시간이 걸리거나 별도의 특성이 있을 때, 연속으로 흐를 때
succession flow cruise.arrival to dropOff.location;cruise가 끝난 뒤에 전달이 시작되고, 전달이 끝난 뒤에야 dropOff가 시작합니다.앞 단계의 결과물을 받아야 다음 단계를 시작할 때
action def Deliver {
    action cruise : Cruise;
    action dropOff : DropOff;

    succession flow cruise.arrival to dropOff.location;
}

succession flow는 순서와 전달을 한 번에 정하므로, 이 선언이 있으면 first cruise then dropOff;를 따로 적지 않아도 됩니다.

flow definition으로 flow의 종류를 정의할 수 있습니다. flow definition은 9장의 connection definition처럼 end를 선언하고, 물려받은 payload를 재정의해 payload의 type을 정합니다.

flow def PowerFlow {
    ref item :>> payload : ElectricPower;
    end part supplier : Battery;
    end part consumer : FlightController;
}

10장에서 본 대로 interface definition의 본문에 flow를 선언해 두면, 그 interface로 port를 이을 때마다 flow가 함께 생깁니다.

send와 accept

flow는 보내는 쪽과 받는 쪽을 한 선언에서 연결합니다. 양쪽에서 상대를 직접 참조하지 않고 따로 설계하려면 send action과 accept action을 씁니다. 보내는 쪽은 무엇을 어디로 내보낼지만 적고, 받는 쪽은 무엇을 어디에서 받을지만 적습니다.

part def GroundStation {
    port commandPort : CommandPort;

    action dispatch {
        in target : Position;

        send new FlightCommand(target, FlightMode::autonomous) via commandPort;
        then accept report : StatusReport via commandPort;
    }
}

send action은 send 뒤에 payload를 내는 expression을 적고, via 뒤에 내보내는 곳을 적습니다. 여기서는 new로 FlightCommand를 만들어 commandPort로 내보냅니다. accept action은 accept 뒤에 받을 payload의 이름과 type을 적고, via 뒤에 받는 곳을 적습니다. dispatch는 명령을 보낸 다음 StatusReport가 올 때까지 기다립니다.

받는 쪽에서는 accept로 받은 payload를 이름으로 가리켜 다음 action에 씁니다.

part def Drone {
    part battery : Battery;
    port commandPort : ~CommandPort;

    action respond {
        accept command : FlightCommand via commandPort;
        then action fly : Cruise {
            in destination = command.target;
        }
        then send new StatusReport(fly.arrival, battery.chargeLevel) via commandPort;
    }
}

두 part 가운데 어느 쪽도 상대를 가리키지 않습니다. 둘을 잇는 것은 10장의 interface입니다. DeliveryService가 groundStation.commandPort와 drones.commandPort를 interface로 이었으므로, 지상 통제소가 자기 port로 내보낸 명령은 드론의 port에 닿고, 드론이 내보낸 보고는 지상 통제소의 port에 닿습니다.

보내는 곳과 받는 곳을 적는 방법은 다음과 같습니다.

표기뜻
send 식 via p;port p로 내보냅니다. 받는 쪽은 p에 이어진 interface가 정합니다.
send 식 to x;x에게 직접 보냅니다.
accept n : T via p;port p로 들어온 T를 받습니다.
accept n : T;받는 곳을 적지 않았습니다. 이 action을 담은 part가 받습니다.

via와 to를 모두 적지 않은 send action에서는 그 action을 담은 part가 보내는 쪽이 됩니다. 이 기본값은 action이 part에 composite로 딸려 있을 때 적용됩니다. perform action은 referential이므로, 그 안의 send와 accept는 part가 아닌 그 perform action usage를 기준으로 삼습니다.

accept action은 18장에서 transition의 trigger로 사용한 action입니다. 받을 payload를 적는 자리에 when 조건, at 시각, after 시간을 쓰면 조건이 바뀌거나 지정한 시각에 이르거나 지정한 시간이 지나기를 기다립니다.

message: 주고받는다는 것만 적기

설계 초기에는 누가 누구와 무엇을 주고받는지만 정하고, 어느 port와 어느 action이 관여하는지는 나중에 정합니다. message가 이 수준의 flow입니다.

part def DeliveryService {
    part groundStation : GroundStation {
        event occurrence commandSent;
        event occurrence reportReceived;
    }
    part drone : Drone {
        event occurrence commandReceived;
        event occurrence reportSent;
    }

    message command of FlightCommand
        from groundStation.commandSent to drone.commandReceived;
    message report of StatusReport
        from drone.reportSent to groundStation.reportReceived;

    first drone.commandReceived then drone.reportSent;
}
sequenceDiagram
    participant G as groundStation
    participant D as drone
    G->>D: command : FlightCommand
    D->>G: report : StatusReport

message는 from 뒤에 보내는 사건을, to 뒤에 받는 사건을 적습니다. 사건은 15장의 event occurrence usage입니다. groundStation.commandSent는 지상 통제소의 lifetime 안에서 명령을 보내는 일이 일어난다는 것만 말하고, 그 일을 어떤 action이 하는지는 정하지 않습니다. 사건 사이의 순서는 succession으로 적습니다. 위 모델은 드론이 명령을 받은 뒤에 보고를 보낸다고 정했습니다.

message로 적은 상호작용은 설계가 진행되면서 구체화합니다. 사건은 send action과 accept action으로, message는 port 사이의 flow나 interface를 지나는 전달로 바뀝니다. 앞 절의 dispatch와 respond가 이 message 둘을 구체화한 것입니다.

KerML에서 보면

KerML에서 무언가가 옮겨 가는 일은 Transfers::Transfer가 분류합니다. transfer는 performance이면서 보내는 쪽과 받는 쪽 사이의 link입니다. 이렇게 behavior이면서 association인 classifier를 interaction이라고 하고, interaction을 type으로 갖는 step이면서 connector인 feature를 flow라고 합니다.

SysMLKerML기준 library element
flow definition (FlowDefinition)InteractionFlows::MessageAction
message (FlowUsage)FlowFlows::messages
flow (FlowUsage)FlowFlows::flows
succession flow (SuccessionFlowUsage)SuccessionFlowFlows::successionFlows
send action (SendActionUsage)StepActions::sendActions
accept action (AcceptActionUsage)StepActions::acceptActions

FlowUsage는 ActionUsage, ConnectorAsUsage, KerML의 Flow를 함께 특수화합니다. flow는 action이고, 9장의 connection처럼 두 feature를 잇는 connector입니다. 그래서 flow에 이름과 multiplicity를 주고, end를 선언하고, 다른 flow를 특수화할 수 있습니다.

library에서 세 가지 flow는 단계적인 특수화 관계를 이룹니다. Flows::Message는 Transfers::Transfer를, Flows::Flow는 Message와 Transfers::FlowTransfer를, Flows::SuccessionFlow는 Flow와 Transfers::FlowTransferBefore를 특수화합니다. message에서 flow로, flow에서 succession flow로 갈수록 어떤 조건이 추가되는지 library에서 확인할 수 있습니다.

send action과 accept action도 library의 action definition Actions::SendAction과 Actions::AcceptAction을 type으로 갖는 action usage입니다. send … via … to …는 SendAction의 세 parameter인 payload, sender, receiver에 값을 묶는 축약 표기입니다.

KerML 표기법에도 flow와 succession flow 키워드가 있습니다. message, send, accept에 해당하는 키워드는 없습니다.

struct Battery {
    out var feature power : ElectricPower;
}

struct FlightController {
    in var feature power : ElectricPower;
}

struct Drone {
    composite feature battery : Battery;
    composite feature flightController : FlightController;

    flow of ElectricPower from battery.power to flightController.power;
}

구문 요약

구문뜻
flow a.x to b.y;a의 출력 x에서 b의 입력 y로 가는 flow입니다.
flow f of T from a.x to b.y;이름이 f이고 payload의 type이 T인 flow입니다.
succession flow a.x to b.y;a가 끝난 뒤에 옮기고, 그 뒤에 b가 시작하는 flow입니다.
flow def F { ref item :>> payload : T; end … }flow definition입니다.
message m of T from a.e1 to b.e2;사건 e1에서 사건 e2로 가는 message입니다.
send 식 via p;, send 식 to x;send action입니다.
accept n : T via p;accept action입니다. 받은 payload를 n으로 가리킵니다.
accept when 조건;, accept after 시간;조건의 변화나 시간을 기다립니다.

명세에서 찾아보기

주제조항
flow와 messageSysML 7.16, 8.3.16, 8.4.12
send actionSysML 7.17.7
accept action과 triggerSysML 7.17.8
interface를 지나는 전달SysML 7.14.2
Flows librarySysML 9.2.9
interaction과 flowKerML 7.4.10
Transfers libraryKerML 9.2.7