Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
ResourceService resourceService = ...;

ResourceConsumer consumer = IntentId.valueOf(1);
DeviceId device = DeviceId.deviceId("foo");
PortNumber port = PortNumber.portNumber(1);
VlanId vlan = VlanId.vlanId((short) 100);

// create a VLAN ID resource on port 1 on device "foo"
DiscreteResource vlanRes = Resources.discrete(device, port, vlan).resource();

// create a bandwidth resource representing 1000bps on port 1 on device "foo"
ContinuousResource bandwidthRes = Resources.continuous(device, port, Bandwidth.class).resource(1000);

// allocate the VLAN ID resource, then release it
resourceService.allocate(consumer, vlanRes).ifPresent(alloc -> resourceService.release(alloc));

// allocate the bandwidth resource, then release it
resourceService.allocate(consumer, bandwidthRes).ifPresent(alloc -> resourceService.release(alloc));

// create a discrete resource ID
Resources.discrete(device, port).id();

// create a continuous resource ID
Resources.continuous(device, port, Bandwidth.class).id();

...