├── .gitignore ├── LICENSE ├── README.md ├── Tentative-Agenda.md ├── activity-feed └── src │ └── main │ ├── java │ └── amaethon │ │ ├── Auction.java │ │ ├── AuctionHouse.java │ │ ├── AuctionService.java │ │ ├── AutomatedClient.java │ │ ├── Bidder.java │ │ ├── Model.java │ │ ├── RunExercise.java │ │ └── generated │ │ ├── AuctionDecoder.java │ │ ├── AuctionEncoder.java │ │ ├── AuctionListDecoder.java │ │ ├── AuctionListEncoder.java │ │ ├── AuctionOverDecoder.java │ │ ├── AuctionOverEncoder.java │ │ ├── BidDecoder.java │ │ ├── BidEncoder.java │ │ ├── GroupSizeEncodingDecoder.java │ │ ├── GroupSizeEncodingEncoder.java │ │ ├── MessageHeaderDecoder.java │ │ ├── MessageHeaderEncoder.java │ │ ├── MetaAttribute.java │ │ ├── NewAuctionDecoder.java │ │ ├── NewAuctionEncoder.java │ │ ├── NewHighBidDecoder.java │ │ ├── NewHighBidEncoder.java │ │ ├── VarDataEncodingDecoder.java │ │ └── VarDataEncodingEncoder.java │ └── resources │ ├── Amaethon-schema.xml │ └── fpl │ └── SimpleBinary1-0.xsd ├── advanced-service └── src │ └── main │ ├── java │ └── amaethon │ │ ├── Auction.java │ │ ├── AuctionHouse.java │ │ ├── AuctionService.java │ │ ├── AutomatedClient.java │ │ ├── Bidder.java │ │ ├── Model.java │ │ ├── RunExercise.java │ │ └── generated │ │ ├── AuctionDecoder.java │ │ ├── AuctionEncoder.java │ │ ├── AuctionListDecoder.java │ │ ├── AuctionListEncoder.java │ │ ├── AuctionOverDecoder.java │ │ ├── AuctionOverEncoder.java │ │ ├── AuctionType.java │ │ ├── BidDecoder.java │ │ ├── BidEncoder.java │ │ ├── FixedPriceAuctionDecoder.java │ │ ├── FixedPriceAuctionEncoder.java │ │ ├── FixedPriceAuctionUpdateDecoder.java │ │ ├── FixedPriceAuctionUpdateEncoder.java │ │ ├── GroupSizeEncodingDecoder.java │ │ ├── GroupSizeEncodingEncoder.java │ │ ├── MessageHeaderDecoder.java │ │ ├── MessageHeaderEncoder.java │ │ ├── MetaAttribute.java │ │ ├── NewAuctionDecoder.java │ │ ├── NewAuctionEncoder.java │ │ ├── NewHighBidDecoder.java │ │ ├── NewHighBidEncoder.java │ │ ├── VarDataEncodingDecoder.java │ │ └── VarDataEncodingEncoder.java │ └── resources │ ├── Amaethon-schema.xml │ └── fpl │ └── SimpleBinary1-0.xsd ├── basic-service └── src │ └── main │ ├── java │ └── amaethon │ │ ├── Auction.java │ │ ├── AuctionHouse.java │ │ ├── AuctionService.java │ │ ├── AutomatedClient.java │ │ ├── Bidder.java │ │ ├── Model.java │ │ ├── RunExercise.java │ │ └── generated │ │ ├── AuctionDecoder.java │ │ ├── AuctionEncoder.java │ │ ├── BidDecoder.java │ │ ├── BidEncoder.java │ │ ├── MessageHeaderDecoder.java │ │ ├── MessageHeaderEncoder.java │ │ ├── MetaAttribute.java │ │ ├── PriceDecoder.java │ │ ├── PriceEncoder.java │ │ ├── VarDataEncodingDecoder.java │ │ └── VarDataEncodingEncoder.java │ └── resources │ ├── Amaethon-schema.xml │ └── fpl │ └── SimpleBinary1-0.xsd ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── solutions ├── activity-feed └── src │ └── main │ ├── java │ └── amaethon │ │ ├── Auction.java │ │ ├── AuctionHouse.java │ │ ├── AuctionService.java │ │ ├── AutomatedClient.java │ │ ├── Bidder.java │ │ ├── Model.java │ │ ├── RunExercise.java │ │ └── generated │ │ ├── AuctionDecoder.java │ │ ├── AuctionEncoder.java │ │ ├── AuctionListDecoder.java │ │ ├── AuctionListEncoder.java │ │ ├── AuctionOverDecoder.java │ │ ├── AuctionOverEncoder.java │ │ ├── BidDecoder.java │ │ ├── BidEncoder.java │ │ ├── GroupSizeEncodingDecoder.java │ │ ├── GroupSizeEncodingEncoder.java │ │ ├── MessageHeaderDecoder.java │ │ ├── MessageHeaderEncoder.java │ │ ├── MetaAttribute.java │ │ ├── NewAuctionDecoder.java │ │ ├── NewAuctionEncoder.java │ │ ├── NewHighBidDecoder.java │ │ ├── NewHighBidEncoder.java │ │ ├── VarDataEncodingDecoder.java │ │ └── VarDataEncodingEncoder.java │ └── resources │ ├── Amaethon-schema.xml │ └── fpl │ └── SimpleBinary1-0.xsd ├── advanced-service └── src │ └── main │ ├── java │ └── amaethon │ │ ├── Auction.java │ │ ├── AuctionHouse.java │ │ ├── AuctionService.java │ │ ├── AutomatedClient.java │ │ ├── Bidder.java │ │ ├── Model.java │ │ ├── RunExercise.java │ │ └── generated │ │ ├── AuctionDecoder.java │ │ ├── AuctionEncoder.java │ │ ├── AuctionListDecoder.java │ │ ├── AuctionListEncoder.java │ │ ├── AuctionOverDecoder.java │ │ ├── AuctionOverEncoder.java │ │ ├── AuctionType.java │ │ ├── BidDecoder.java │ │ ├── BidEncoder.java │ │ ├── FixedPriceAuctionDecoder.java │ │ ├── FixedPriceAuctionEncoder.java │ │ ├── FixedPriceAuctionUpdateDecoder.java │ │ ├── FixedPriceAuctionUpdateEncoder.java │ │ ├── GroupSizeEncodingDecoder.java │ │ ├── GroupSizeEncodingEncoder.java │ │ ├── MessageHeaderDecoder.java │ │ ├── MessageHeaderEncoder.java │ │ ├── MetaAttribute.java │ │ ├── NewAuctionDecoder.java │ │ ├── NewAuctionEncoder.java │ │ ├── NewHighBidDecoder.java │ │ ├── NewHighBidEncoder.java │ │ ├── VarDataEncodingDecoder.java │ │ └── VarDataEncodingEncoder.java │ └── resources │ ├── Amaethon-schema.xml │ └── fpl │ └── SimpleBinary1-0.xsd └── basic-service └── src └── main ├── java └── amaethon │ ├── Auction.java │ ├── AuctionHouse.java │ ├── AuctionService.java │ ├── AutomatedClient.java │ ├── Bidder.java │ ├── Model.java │ ├── RunExercise.java │ └── generated │ ├── AuctionDecoder.java │ ├── AuctionEncoder.java │ ├── BidDecoder.java │ ├── BidEncoder.java │ ├── MessageHeaderDecoder.java │ ├── MessageHeaderEncoder.java │ ├── MetaAttribute.java │ ├── PriceDecoder.java │ ├── PriceEncoder.java │ ├── VarDataEncodingDecoder.java │ └── VarDataEncodingEncoder.java └── resources ├── Amaethon-schema.xml └── fpl └── SimpleBinary1-0.xsd /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | .gradle 3 | *~ 4 | build 5 | *.iml 6 | .idea 7 | 8 | # Mobile Tools for Java (J2ME) 9 | .mtj.tmp/ 10 | 11 | # Package Files # 12 | *.jar 13 | *.war 14 | *.ear 15 | 16 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 17 | hs_err_pid* 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Amaethon 2 | ======== 3 | 4 | Auctioning with Aeron and SBE! 5 | 6 | Why Amaethon? 7 | ------------- 8 | 9 | [Amaethon](http://en.wikipedia.org/wiki/Amaethon) 10 | 11 | Directory Structure 12 | ------------------- 13 | 14 | Basic Service (Exercise 1) 15 | 16 | basic-service 17 | 18 | Service with Activity Feed (Exercise 2) 19 | 20 | activity-feed 21 | 22 | Advanced Service (Exercise 3) 23 | 24 | advanced-service 25 | 26 | Solutions 27 | 28 | solutions 29 | 30 | Individual Solutions 31 | 32 | solutions/basic-service 33 | solutions/activity-feed 34 | solutions/advanced-service 35 | 36 | Building 37 | -------- 38 | 39 | You require the following to build Amaethon: 40 | 41 | * Latest stable [Oracle JDK 8](http://www.oracle.com/technetwork/java/) 42 | 43 | You must first build and install [Agrona](https://github.com/real-logic/Agrona) into the local maven repository 44 | 45 | $ ./gradlew 46 | 47 | After Agrona is compiled and installed, then you can build Amaethon. 48 | 49 | Full clean and build of all modules 50 | 51 | $ ./gradlew 52 | 53 | Running Exercises 54 | ----------------- 55 | 56 | Once successfully built, the Amaethon exercises can be run 57 | 58 | $ ./gradlew :basic-service:run 59 | $ ./gradlew :activity-feed:run 60 | $ ./gradlew :advanced-service:run 61 | 62 | Running Exercise Solutions 63 | -------------------------- 64 | 65 | Once successfully built, the Amaethon solutions to the exercises can be run 66 | 67 | $ ./gradlew :solutions:basic-service:run 68 | $ ./gradlew :solutions:activity-feed:run 69 | $ ./gradlew :solutions:advanced-service:run 70 | 71 | Generating SBE Codecs 72 | --------------------- 73 | 74 | The SBE codecs for all the exercises are included. But if you want to generate the codecs yourself, then you will 75 | need to have the latest SBE in a directory along side the Amaethon directory. 76 | 77 | $ cd .. 78 | $ git clone https://github.com/real-logic/simple-binary-encoding.git 79 | $ cd simple-binary-encoding 80 | $ ./gradlew 81 | 82 | Then you may build Amaethon. This assumes you are currently in the `simple-binary-encoding` directory from 83 | the last set of steps. 84 | 85 | $ cd ../Amaethon 86 | $ ./gradlew 87 | -------------------------------------------------------------------------------- /Tentative-Agenda.md: -------------------------------------------------------------------------------- 1 | # Low Latency Communications Agenda (9am - 4pm with 12-1pm Lunch) 2 | 3 | Intro to SBE: 9-10am 4 | * Break: 10 min 5 | 6 | Intro to Aeron: 10-11am 7 | * Break: 10 min 8 | 9 | Exercise 1: 11-12pm 10 | * intro to auctions and exercises: 20 min 11 | * given domain model of an auction system, turn it into a service that listens on an Aeron stream 12 | (receiving and decoding) for the following commands: 13 | 1. new auction 14 | 1. bid on auction 15 | * SBE schemas are provided for the commands 16 | 17 | Exercise 2: 1-2pm 18 | * add activity feed to auction service (sending and encoding). Events are: 19 | 1. new auction 20 | 1. new high bid on auction 21 | 1. auction won 22 | 1. list of active auctions (periodic) 23 | * SBE schemas are provided for the events on the activity feed 24 | * break: 10 min 25 | 26 | Exercise 3: 2-3pm 27 | * discussion of how schema's could work (new version?, new templateIds?, deprecate?): 15 min 28 | * add a new type of auction to the service. A fixed amount of items. 29 | * new domain model including new auction type provided 30 | * SBE schemas updated for commands and activity feed events 31 | * break: 10 min 32 | 33 | Exercise 4: 3-4pm (If we have time and the WiFi cooperates!) 34 | -------------------------------------------------------------------------------- /activity-feed/src/main/java/amaethon/Auction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import java.util.concurrent.TimeUnit; 21 | 22 | /** 23 | * Encapsulation of an Auction. Instances will be re-used by {@link AuctionHouse}. 24 | */ 25 | public class Auction 26 | { 27 | private static final long LINGER_TIMEOUT_NANOS = TimeUnit.SECONDS.toNanos(10); 28 | 29 | /* 30 | * INACTIVE means Auction not valid 31 | * ACTIVE means Auction is accepting bids 32 | * OVER means Auction is over (Auction will linger for a period of time before being re-used) 33 | */ 34 | enum State 35 | { 36 | INACTIVE, ACTIVE, OVER 37 | } 38 | 39 | private byte[] nameInBytes = new byte[1024]; 40 | private int nameLength; 41 | private int id; 42 | private long expiration; 43 | private long currentHighBid; 44 | private long currentHighBidderId; 45 | private State state; 46 | 47 | public Auction() 48 | { 49 | this.state = State.INACTIVE; 50 | } 51 | 52 | public void reset(final int id, final byte[] name, final int nameLength, final long expiration, final long reserveValue) 53 | { 54 | this.id = id; 55 | System.arraycopy(name, 0, this.nameInBytes, 0, name.length); 56 | this.nameLength = nameLength; 57 | this.expiration = expiration; 58 | this.currentHighBid = reserveValue; 59 | this.currentHighBidderId = Bidder.INVALID_BIDDER; 60 | this.state = State.ACTIVE; 61 | } 62 | 63 | public boolean isInactive() 64 | { 65 | return (State.INACTIVE == state); 66 | } 67 | 68 | public boolean isActive() 69 | { 70 | return (State.ACTIVE == state); 71 | } 72 | 73 | public int id() 74 | { 75 | return id; 76 | } 77 | 78 | public String name() 79 | { 80 | return new String(nameInBytes, 0, nameLength); 81 | } 82 | 83 | public byte[] nameInBytes() 84 | { 85 | return nameInBytes; 86 | } 87 | 88 | public int nameLength() 89 | { 90 | return nameLength; 91 | } 92 | 93 | public long expiration() 94 | { 95 | return expiration; 96 | } 97 | 98 | public long highBid() 99 | { 100 | return currentHighBid; 101 | } 102 | 103 | public long highBidder() 104 | { 105 | return currentHighBidderId; 106 | } 107 | 108 | // return 0 for nothing new or >0 for activity 109 | public int onAdvanceTime(final long now) 110 | { 111 | int result = 0; 112 | 113 | if (State.ACTIVE == state && now > expiration) 114 | { 115 | state = State.OVER; 116 | result = 1; 117 | } 118 | else if (State.OVER == state && now > (expiration + LINGER_TIMEOUT_NANOS)) 119 | { 120 | state = State.INACTIVE; 121 | } 122 | 123 | return result; 124 | } 125 | 126 | // True if high bid. False if not. 127 | public boolean bid(final long bidderId, final long value) 128 | { 129 | boolean result = false; 130 | 131 | if (State.ACTIVE == state && value > currentHighBid) 132 | { 133 | currentHighBid = value; 134 | currentHighBidderId = bidderId; 135 | result = true; 136 | } 137 | 138 | return result; 139 | } 140 | 141 | public void cancel() 142 | { 143 | this.currentHighBidderId = Bidder.INVALID_BIDDER; 144 | this.state = State.OVER; 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /activity-feed/src/main/java/amaethon/Bidder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import java.util.Arrays; 21 | 22 | /** 23 | * Encapsulation of a bidder 24 | */ 25 | public class Bidder 26 | { 27 | public static final long INVALID_BIDDER = -1; 28 | 29 | private final byte[] name; 30 | private final long id; 31 | private long budget; 32 | 33 | public Bidder(final byte[] name, final long bidderId, final long budget) 34 | { 35 | this.name = Arrays.copyOf(name, name.length); 36 | this.id = bidderId; 37 | this.budget = budget; 38 | } 39 | 40 | public byte[] name() 41 | { 42 | return name; 43 | } 44 | 45 | public long id() 46 | { 47 | return id; 48 | } 49 | 50 | public long budget() 51 | { 52 | return budget; 53 | } 54 | 55 | public void decrementBudget(final long price) 56 | { 57 | budget -= price; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /activity-feed/src/main/java/amaethon/Model.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import java.util.function.Consumer; 21 | 22 | /** 23 | * Interface for an Auction House 24 | */ 25 | public interface Model 26 | { 27 | // add an auction 28 | int add(final byte[] name, final int nameLength, final long expiration, final long reserveValue); 29 | 30 | // cancel an auction 31 | void cancel(final int auctionId); 32 | 33 | // bid on an auction. True if high bid, False if not 34 | boolean bid(final int auctionId, final long bidderId, final long value); 35 | 36 | // iterator over all non-inactive auctions (for activity feed and for advancing time on auctions) 37 | void forEach(final Consumer consumer); 38 | 39 | // done to add a new bidding account to the system 40 | void addBidder(final byte[] name, final long bidderId, final long budget); 41 | } -------------------------------------------------------------------------------- /activity-feed/src/main/java/amaethon/RunExercise.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import uk.co.real_logic.aeron.driver.MediaDriver; 21 | 22 | import java.util.concurrent.TimeUnit; 23 | import java.util.concurrent.locks.LockSupport; 24 | 25 | /** 26 | * Runner for the exercise that has a contained Media Driver, AuctionService and AutomatedClient 27 | */ 28 | public class RunExercise 29 | { 30 | public static final String SUBMISSION_CHANNEL = "aeron:udp?remote=localhost:43456"; 31 | public static final int SUBMISSION_STREAM_ID = 1; 32 | public static final String ACTIVITY_FEED_CHANNEL = "aeron:udp?remote=localhost:43457"; // could be multicast 33 | public static final int ACTIVITY_FEED_STREAM_ID = 1; 34 | 35 | public static void main(final String[] args) throws Exception 36 | { 37 | final MediaDriver.Context ctx = new MediaDriver.Context(); 38 | final MediaDriver mediaDriver = MediaDriver.launch(ctx.dirsDeleteOnStart(true)); 39 | final AuctionService service = 40 | new AuctionService(SUBMISSION_CHANNEL, SUBMISSION_STREAM_ID, ACTIVITY_FEED_CHANNEL, ACTIVITY_FEED_STREAM_ID); 41 | final Thread serviceThread = new Thread(service); 42 | final AuctionHouse house = service.house(); 43 | 44 | serviceThread.setName("AuctionService"); 45 | serviceThread.start(); 46 | 47 | try (final AutomatedClient client = 48 | new AutomatedClient(SUBMISSION_CHANNEL, SUBMISSION_STREAM_ID, ACTIVITY_FEED_CHANNEL, ACTIVITY_FEED_STREAM_ID)) 49 | { 50 | house.addBidder("tmontgomery".getBytes(), 1, 0); 51 | house.addBidder("mjpt777".getBytes(), 2, 0); 52 | house.addBidder("RichardWarburton".getBytes(), 3, 0); 53 | 54 | client.auction("Star Wars Force Awakens Pre-Pre-Release", 1000000000, "00:00:10"); 55 | client.bid(0, 1, 1000000000 + 1); 56 | client.auction("Issue #1000", 0, "00:00:05"); 57 | client.bid(1, 2, 1); 58 | client.bid(1, 3, 1); 59 | client.bid(1, 1, 2); 60 | 61 | final long now = System.nanoTime(); 62 | final long end = now + TimeUnit.SECONDS.toNanos(15); 63 | 64 | while (System.nanoTime() < end) 65 | { 66 | client.pollActivityFeed(); 67 | LockSupport.parkNanos(TimeUnit.MICROSECONDS.toNanos(50)); 68 | } 69 | } 70 | 71 | service.shutdown(); 72 | serviceThread.join(); 73 | service.close(); 74 | mediaDriver.close(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /activity-feed/src/main/java/amaethon/generated/AuctionOverEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class AuctionOverEncoder 25 | { 26 | public static final int BLOCK_LENGTH = 20; 27 | public static final int TEMPLATE_ID = 5; 28 | public static final int SCHEMA_ID = 1; 29 | public static final int SCHEMA_VERSION = 0; 30 | 31 | private final AuctionOverEncoder parentMessage = this; 32 | private MutableDirectBuffer buffer; 33 | protected int offset; 34 | protected int limit; 35 | protected int actingBlockLength; 36 | protected int actingVersion; 37 | 38 | public int sbeBlockLength() 39 | { 40 | return BLOCK_LENGTH; 41 | } 42 | 43 | public int sbeTemplateId() 44 | { 45 | return TEMPLATE_ID; 46 | } 47 | 48 | public int sbeSchemaId() 49 | { 50 | return SCHEMA_ID; 51 | } 52 | 53 | public int sbeSchemaVersion() 54 | { 55 | return SCHEMA_VERSION; 56 | } 57 | 58 | public String sbeSemanticType() 59 | { 60 | return ""; 61 | } 62 | 63 | public int offset() 64 | { 65 | return offset; 66 | } 67 | 68 | public AuctionOverEncoder wrap(final MutableDirectBuffer buffer, final int offset) 69 | { 70 | this.buffer = buffer; 71 | this.offset = offset; 72 | limit(offset + BLOCK_LENGTH); 73 | return this; 74 | } 75 | 76 | public int size() 77 | { 78 | return limit - offset; 79 | } 80 | 81 | public int limit() 82 | { 83 | return limit; 84 | } 85 | 86 | public void limit(final int limit) 87 | { 88 | buffer.checkLimit(limit); 89 | this.limit = limit; 90 | } 91 | 92 | public static int auctionIdNullValue() 93 | { 94 | return -2147483648; 95 | } 96 | 97 | public static int auctionIdMinValue() 98 | { 99 | return -2147483647; 100 | } 101 | 102 | public static int auctionIdMaxValue() 103 | { 104 | return 2147483647; 105 | } 106 | public AuctionOverEncoder auctionId(final int value) 107 | { 108 | CodecUtil.int32Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 109 | return this; 110 | } 111 | 112 | public static long winningBidderIdNullValue() 113 | { 114 | return -9223372036854775808L; 115 | } 116 | 117 | public static long winningBidderIdMinValue() 118 | { 119 | return -9223372036854775807L; 120 | } 121 | 122 | public static long winningBidderIdMaxValue() 123 | { 124 | return 9223372036854775807L; 125 | } 126 | public AuctionOverEncoder winningBidderId(final long value) 127 | { 128 | CodecUtil.int64Put(buffer, offset + 4, value, java.nio.ByteOrder.LITTLE_ENDIAN); 129 | return this; 130 | } 131 | 132 | public static long winningBidNullValue() 133 | { 134 | return -9223372036854775808L; 135 | } 136 | 137 | public static long winningBidMinValue() 138 | { 139 | return -9223372036854775807L; 140 | } 141 | 142 | public static long winningBidMaxValue() 143 | { 144 | return 9223372036854775807L; 145 | } 146 | public AuctionOverEncoder winningBid(final long value) 147 | { 148 | CodecUtil.int64Put(buffer, offset + 12, value, java.nio.ByteOrder.LITTLE_ENDIAN); 149 | return this; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /activity-feed/src/main/java/amaethon/generated/BidEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class BidEncoder 25 | { 26 | public static final int BLOCK_LENGTH = 20; 27 | public static final int TEMPLATE_ID = 2; 28 | public static final int SCHEMA_ID = 1; 29 | public static final int SCHEMA_VERSION = 0; 30 | 31 | private final BidEncoder parentMessage = this; 32 | private MutableDirectBuffer buffer; 33 | protected int offset; 34 | protected int limit; 35 | protected int actingBlockLength; 36 | protected int actingVersion; 37 | 38 | public int sbeBlockLength() 39 | { 40 | return BLOCK_LENGTH; 41 | } 42 | 43 | public int sbeTemplateId() 44 | { 45 | return TEMPLATE_ID; 46 | } 47 | 48 | public int sbeSchemaId() 49 | { 50 | return SCHEMA_ID; 51 | } 52 | 53 | public int sbeSchemaVersion() 54 | { 55 | return SCHEMA_VERSION; 56 | } 57 | 58 | public String sbeSemanticType() 59 | { 60 | return ""; 61 | } 62 | 63 | public int offset() 64 | { 65 | return offset; 66 | } 67 | 68 | public BidEncoder wrap(final MutableDirectBuffer buffer, final int offset) 69 | { 70 | this.buffer = buffer; 71 | this.offset = offset; 72 | limit(offset + BLOCK_LENGTH); 73 | return this; 74 | } 75 | 76 | public int size() 77 | { 78 | return limit - offset; 79 | } 80 | 81 | public int limit() 82 | { 83 | return limit; 84 | } 85 | 86 | public void limit(final int limit) 87 | { 88 | buffer.checkLimit(limit); 89 | this.limit = limit; 90 | } 91 | 92 | public static int auctionIdNullValue() 93 | { 94 | return -2147483648; 95 | } 96 | 97 | public static int auctionIdMinValue() 98 | { 99 | return -2147483647; 100 | } 101 | 102 | public static int auctionIdMaxValue() 103 | { 104 | return 2147483647; 105 | } 106 | public BidEncoder auctionId(final int value) 107 | { 108 | CodecUtil.int32Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 109 | return this; 110 | } 111 | 112 | public static long bidderIdNullValue() 113 | { 114 | return -9223372036854775808L; 115 | } 116 | 117 | public static long bidderIdMinValue() 118 | { 119 | return -9223372036854775807L; 120 | } 121 | 122 | public static long bidderIdMaxValue() 123 | { 124 | return 9223372036854775807L; 125 | } 126 | public BidEncoder bidderId(final long value) 127 | { 128 | CodecUtil.int64Put(buffer, offset + 4, value, java.nio.ByteOrder.LITTLE_ENDIAN); 129 | return this; 130 | } 131 | 132 | public static long valueNullValue() 133 | { 134 | return -9223372036854775808L; 135 | } 136 | 137 | public static long valueMinValue() 138 | { 139 | return -9223372036854775807L; 140 | } 141 | 142 | public static long valueMaxValue() 143 | { 144 | return 9223372036854775807L; 145 | } 146 | public BidEncoder value(final long value) 147 | { 148 | CodecUtil.int64Put(buffer, offset + 12, value, java.nio.ByteOrder.LITTLE_ENDIAN); 149 | return this; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /activity-feed/src/main/java/amaethon/generated/GroupSizeEncodingDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.DirectBuffer; 23 | 24 | public class GroupSizeEncodingDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public GroupSizeEncodingDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 4; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | 58 | public int blockLength() 59 | { 60 | return CodecUtil.uint16Get(buffer, offset + 0, java.nio.ByteOrder.LITTLE_ENDIAN); 61 | } 62 | 63 | 64 | public static int numInGroupNullValue() 65 | { 66 | return 65535; 67 | } 68 | 69 | public static int numInGroupMinValue() 70 | { 71 | return 0; 72 | } 73 | 74 | public static int numInGroupMaxValue() 75 | { 76 | return 65534; 77 | } 78 | 79 | public int numInGroup() 80 | { 81 | return CodecUtil.uint16Get(buffer, offset + 2, java.nio.ByteOrder.LITTLE_ENDIAN); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /activity-feed/src/main/java/amaethon/generated/GroupSizeEncodingEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class GroupSizeEncodingEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public GroupSizeEncodingEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 4; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | public GroupSizeEncodingEncoder blockLength(final int value) 58 | { 59 | CodecUtil.uint16Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 60 | return this; 61 | } 62 | 63 | public static int numInGroupNullValue() 64 | { 65 | return 65535; 66 | } 67 | 68 | public static int numInGroupMinValue() 69 | { 70 | return 0; 71 | } 72 | 73 | public static int numInGroupMaxValue() 74 | { 75 | return 65534; 76 | } 77 | public GroupSizeEncodingEncoder numInGroup(final int value) 78 | { 79 | CodecUtil.uint16Put(buffer, offset + 2, value, java.nio.ByteOrder.LITTLE_ENDIAN); 80 | return this; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /activity-feed/src/main/java/amaethon/generated/MessageHeaderDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.DirectBuffer; 23 | 24 | public class MessageHeaderDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public MessageHeaderDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 8; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | 58 | public int blockLength() 59 | { 60 | return CodecUtil.uint16Get(buffer, offset + 0, java.nio.ByteOrder.LITTLE_ENDIAN); 61 | } 62 | 63 | 64 | public static int templateIdNullValue() 65 | { 66 | return 65535; 67 | } 68 | 69 | public static int templateIdMinValue() 70 | { 71 | return 0; 72 | } 73 | 74 | public static int templateIdMaxValue() 75 | { 76 | return 65534; 77 | } 78 | 79 | public int templateId() 80 | { 81 | return CodecUtil.uint16Get(buffer, offset + 2, java.nio.ByteOrder.LITTLE_ENDIAN); 82 | } 83 | 84 | 85 | public static int schemaIdNullValue() 86 | { 87 | return 65535; 88 | } 89 | 90 | public static int schemaIdMinValue() 91 | { 92 | return 0; 93 | } 94 | 95 | public static int schemaIdMaxValue() 96 | { 97 | return 65534; 98 | } 99 | 100 | public int schemaId() 101 | { 102 | return CodecUtil.uint16Get(buffer, offset + 4, java.nio.ByteOrder.LITTLE_ENDIAN); 103 | } 104 | 105 | 106 | public static int versionNullValue() 107 | { 108 | return 65535; 109 | } 110 | 111 | public static int versionMinValue() 112 | { 113 | return 0; 114 | } 115 | 116 | public static int versionMaxValue() 117 | { 118 | return 65534; 119 | } 120 | 121 | public int version() 122 | { 123 | return CodecUtil.uint16Get(buffer, offset + 6, java.nio.ByteOrder.LITTLE_ENDIAN); 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /activity-feed/src/main/java/amaethon/generated/MessageHeaderEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class MessageHeaderEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public MessageHeaderEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 8; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | public MessageHeaderEncoder blockLength(final int value) 58 | { 59 | CodecUtil.uint16Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 60 | return this; 61 | } 62 | 63 | public static int templateIdNullValue() 64 | { 65 | return 65535; 66 | } 67 | 68 | public static int templateIdMinValue() 69 | { 70 | return 0; 71 | } 72 | 73 | public static int templateIdMaxValue() 74 | { 75 | return 65534; 76 | } 77 | public MessageHeaderEncoder templateId(final int value) 78 | { 79 | CodecUtil.uint16Put(buffer, offset + 2, value, java.nio.ByteOrder.LITTLE_ENDIAN); 80 | return this; 81 | } 82 | 83 | public static int schemaIdNullValue() 84 | { 85 | return 65535; 86 | } 87 | 88 | public static int schemaIdMinValue() 89 | { 90 | return 0; 91 | } 92 | 93 | public static int schemaIdMaxValue() 94 | { 95 | return 65534; 96 | } 97 | public MessageHeaderEncoder schemaId(final int value) 98 | { 99 | CodecUtil.uint16Put(buffer, offset + 4, value, java.nio.ByteOrder.LITTLE_ENDIAN); 100 | return this; 101 | } 102 | 103 | public static int versionNullValue() 104 | { 105 | return 65535; 106 | } 107 | 108 | public static int versionMinValue() 109 | { 110 | return 0; 111 | } 112 | 113 | public static int versionMaxValue() 114 | { 115 | return 65534; 116 | } 117 | public MessageHeaderEncoder version(final int value) 118 | { 119 | CodecUtil.uint16Put(buffer, offset + 6, value, java.nio.ByteOrder.LITTLE_ENDIAN); 120 | return this; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /activity-feed/src/main/java/amaethon/generated/MetaAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | public enum MetaAttribute 22 | { 23 | EPOCH, 24 | TIME_UNIT, 25 | SEMANTIC_TYPE 26 | } 27 | -------------------------------------------------------------------------------- /activity-feed/src/main/java/amaethon/generated/NewHighBidEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class NewHighBidEncoder 25 | { 26 | public static final int BLOCK_LENGTH = 28; 27 | public static final int TEMPLATE_ID = 4; 28 | public static final int SCHEMA_ID = 1; 29 | public static final int SCHEMA_VERSION = 0; 30 | 31 | private final NewHighBidEncoder parentMessage = this; 32 | private MutableDirectBuffer buffer; 33 | protected int offset; 34 | protected int limit; 35 | protected int actingBlockLength; 36 | protected int actingVersion; 37 | 38 | public int sbeBlockLength() 39 | { 40 | return BLOCK_LENGTH; 41 | } 42 | 43 | public int sbeTemplateId() 44 | { 45 | return TEMPLATE_ID; 46 | } 47 | 48 | public int sbeSchemaId() 49 | { 50 | return SCHEMA_ID; 51 | } 52 | 53 | public int sbeSchemaVersion() 54 | { 55 | return SCHEMA_VERSION; 56 | } 57 | 58 | public String sbeSemanticType() 59 | { 60 | return ""; 61 | } 62 | 63 | public int offset() 64 | { 65 | return offset; 66 | } 67 | 68 | public NewHighBidEncoder wrap(final MutableDirectBuffer buffer, final int offset) 69 | { 70 | this.buffer = buffer; 71 | this.offset = offset; 72 | limit(offset + BLOCK_LENGTH); 73 | return this; 74 | } 75 | 76 | public int size() 77 | { 78 | return limit - offset; 79 | } 80 | 81 | public int limit() 82 | { 83 | return limit; 84 | } 85 | 86 | public void limit(final int limit) 87 | { 88 | buffer.checkLimit(limit); 89 | this.limit = limit; 90 | } 91 | 92 | public static int auctionIdNullValue() 93 | { 94 | return -2147483648; 95 | } 96 | 97 | public static int auctionIdMinValue() 98 | { 99 | return -2147483647; 100 | } 101 | 102 | public static int auctionIdMaxValue() 103 | { 104 | return 2147483647; 105 | } 106 | public NewHighBidEncoder auctionId(final int value) 107 | { 108 | CodecUtil.int32Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 109 | return this; 110 | } 111 | 112 | public static long highBidderIdNullValue() 113 | { 114 | return -9223372036854775808L; 115 | } 116 | 117 | public static long highBidderIdMinValue() 118 | { 119 | return -9223372036854775807L; 120 | } 121 | 122 | public static long highBidderIdMaxValue() 123 | { 124 | return 9223372036854775807L; 125 | } 126 | public NewHighBidEncoder highBidderId(final long value) 127 | { 128 | CodecUtil.int64Put(buffer, offset + 4, value, java.nio.ByteOrder.LITTLE_ENDIAN); 129 | return this; 130 | } 131 | 132 | public static long highBidNullValue() 133 | { 134 | return -9223372036854775808L; 135 | } 136 | 137 | public static long highBidMinValue() 138 | { 139 | return -9223372036854775807L; 140 | } 141 | 142 | public static long highBidMaxValue() 143 | { 144 | return 9223372036854775807L; 145 | } 146 | public NewHighBidEncoder highBid(final long value) 147 | { 148 | CodecUtil.int64Put(buffer, offset + 12, value, java.nio.ByteOrder.LITTLE_ENDIAN); 149 | return this; 150 | } 151 | 152 | public static long durationLeftNullValue() 153 | { 154 | return -9223372036854775808L; 155 | } 156 | 157 | public static long durationLeftMinValue() 158 | { 159 | return -9223372036854775807L; 160 | } 161 | 162 | public static long durationLeftMaxValue() 163 | { 164 | return 9223372036854775807L; 165 | } 166 | public NewHighBidEncoder durationLeft(final long value) 167 | { 168 | CodecUtil.int64Put(buffer, offset + 20, value, java.nio.ByteOrder.LITTLE_ENDIAN); 169 | return this; 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /activity-feed/src/main/java/amaethon/generated/VarDataEncodingDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.DirectBuffer; 23 | 24 | public class VarDataEncodingDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public VarDataEncodingDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return -1; 41 | } 42 | 43 | public static short lengthNullValue() 44 | { 45 | return (short)255; 46 | } 47 | 48 | public static short lengthMinValue() 49 | { 50 | return (short)0; 51 | } 52 | 53 | public static short lengthMaxValue() 54 | { 55 | return (short)254; 56 | } 57 | 58 | public short length() 59 | { 60 | return CodecUtil.uint8Get(buffer, offset + 0); 61 | } 62 | 63 | 64 | public static short varDataNullValue() 65 | { 66 | return (short)255; 67 | } 68 | 69 | public static short varDataMinValue() 70 | { 71 | return (short)0; 72 | } 73 | 74 | public static short varDataMaxValue() 75 | { 76 | return (short)254; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /activity-feed/src/main/java/amaethon/generated/VarDataEncodingEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class VarDataEncodingEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public VarDataEncodingEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return -1; 41 | } 42 | 43 | public static short lengthNullValue() 44 | { 45 | return (short)255; 46 | } 47 | 48 | public static short lengthMinValue() 49 | { 50 | return (short)0; 51 | } 52 | 53 | public static short lengthMaxValue() 54 | { 55 | return (short)254; 56 | } 57 | public VarDataEncodingEncoder length(final short value) 58 | { 59 | CodecUtil.uint8Put(buffer, offset + 0, value); 60 | return this; 61 | } 62 | 63 | public static short varDataNullValue() 64 | { 65 | return (short)255; 66 | } 67 | 68 | public static short varDataMinValue() 69 | { 70 | return (short)0; 71 | } 72 | 73 | public static short varDataMaxValue() 74 | { 75 | return (short)254; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /activity-feed/src/main/resources/Amaethon-schema.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /advanced-service/src/main/java/amaethon/Bidder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import java.util.Arrays; 21 | 22 | /** 23 | * Encapsulation of a bidder 24 | */ 25 | public class Bidder 26 | { 27 | public static final long INVALID_BIDDER = -1; 28 | 29 | private final byte[] name; 30 | private final long id; 31 | private long budget; 32 | 33 | public Bidder(final byte[] name, final long bidderId, final long budget) 34 | { 35 | this.name = Arrays.copyOf(name, name.length); 36 | this.id = bidderId; 37 | this.budget = budget; 38 | } 39 | 40 | public byte[] name() 41 | { 42 | return name; 43 | } 44 | 45 | public long id() 46 | { 47 | return id; 48 | } 49 | 50 | public long budget() 51 | { 52 | return budget; 53 | } 54 | 55 | public void decrementBudget(final long price) 56 | { 57 | budget -= price; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /advanced-service/src/main/java/amaethon/Model.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import java.util.function.Consumer; 21 | 22 | /** 23 | * Interface for an Auction House 24 | */ 25 | public interface Model 26 | { 27 | // add an auction 28 | int add(final byte[] name, final int nameLength, final long expiration, final long reserveValue); 29 | // exercise 3: add a new auction type 30 | int add(final byte[] name, final int nameLength, final long expiration, final long price, final int quantity); 31 | 32 | // cancel an auction 33 | void cancel(final int auctionId); 34 | 35 | // bid on an auction. True if high bid, False if not 36 | boolean bid(final int auctionId, final long bidderId, final long value); 37 | 38 | // iterator over all non-inactive auctions (for activity feed and for advancing time on auctions) 39 | void forEach(final Consumer consumer); 40 | 41 | // done to add a new bidding account to the system 42 | void addBidder(final byte[] name, final long bidderId, final long budget); 43 | } -------------------------------------------------------------------------------- /advanced-service/src/main/java/amaethon/RunExercise.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import uk.co.real_logic.aeron.driver.MediaDriver; 21 | 22 | import java.util.concurrent.TimeUnit; 23 | import java.util.concurrent.locks.LockSupport; 24 | 25 | /** 26 | * Runner for the exercise that has a contained Media Driver, AuctionService and AutomatedClient 27 | */ 28 | public class RunExercise 29 | { 30 | public static final String SUBMISSION_CHANNEL = "aeron:udp?remote=localhost:43456"; 31 | public static final int SUBMISSION_STREAM_ID = 1; 32 | public static final String ACTIVITY_FEED_CHANNEL = "aeron:udp?remote=localhost:43457"; // could be multicast 33 | public static final int ACTIVITY_FEED_STREAM_ID = 1; 34 | 35 | public static void main(final String[] args) throws Exception 36 | { 37 | final MediaDriver.Context ctx = new MediaDriver.Context(); 38 | final MediaDriver mediaDriver = MediaDriver.launch(ctx.dirsDeleteOnStart(true)); 39 | final AuctionService service = 40 | new AuctionService(SUBMISSION_CHANNEL, SUBMISSION_STREAM_ID, ACTIVITY_FEED_CHANNEL, ACTIVITY_FEED_STREAM_ID); 41 | final Thread serviceThread = new Thread(service); 42 | final AuctionHouse house = service.house(); 43 | 44 | serviceThread.setName("AuctionService"); 45 | serviceThread.start(); 46 | 47 | try (final AutomatedClient client = 48 | new AutomatedClient(SUBMISSION_CHANNEL, SUBMISSION_STREAM_ID, ACTIVITY_FEED_CHANNEL, ACTIVITY_FEED_STREAM_ID)) 49 | { 50 | house.addBidder("tmontgomery".getBytes(), 1, 0); 51 | house.addBidder("mjpt777".getBytes(), 2, 0); 52 | house.addBidder("RichardWarburton".getBytes(), 3, 0); 53 | 54 | client.auction("Star Wars Force Awakens Pre-Pre-Release", 1000000000, "00:00:10"); 55 | client.bid(0, 1, 1000000000 + 1); 56 | client.auction("Issue #1000", 0, "00:00:05"); 57 | client.auction("Fox Force Member", 10000, 5, "00:00:07"); 58 | client.bid(1, 2, 1); 59 | client.bid(1, 3, 1); 60 | client.bid(2, 2, 10000); 61 | client.bid(1, 1, 2); 62 | client.bid(2, 2, 10000); 63 | client.bid(2, 3, 10000); 64 | client.bid(2, 3, 10000); 65 | client.bid(2, 1, 10000); 66 | 67 | final long now = System.nanoTime(); 68 | final long end = now + TimeUnit.SECONDS.toNanos(15); 69 | 70 | while (System.nanoTime() < end) 71 | { 72 | client.pollActivityFeed(); 73 | LockSupport.parkNanos(TimeUnit.MICROSECONDS.toNanos(50)); 74 | } 75 | } 76 | 77 | service.shutdown(); 78 | serviceThread.join(); 79 | service.close(); 80 | mediaDriver.close(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /advanced-service/src/main/java/amaethon/generated/AuctionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | public enum AuctionType 22 | { 23 | Basic((byte)0), 24 | FixedPrice((byte)1), 25 | NULL_VAL((byte)-128); 26 | 27 | private final byte value; 28 | 29 | AuctionType(final byte value) 30 | { 31 | this.value = value; 32 | } 33 | 34 | public byte value() 35 | { 36 | return value; 37 | } 38 | 39 | public static AuctionType get(final byte value) 40 | { 41 | switch (value) 42 | { 43 | case 0: return Basic; 44 | case 1: return FixedPrice; 45 | } 46 | 47 | if ((byte)-128 == value) 48 | { 49 | return NULL_VAL; 50 | } 51 | 52 | throw new IllegalArgumentException("Unknown value: " + value); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /advanced-service/src/main/java/amaethon/generated/BidEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.agrona.MutableDirectBuffer; 22 | import uk.co.real_logic.sbe.codec.java.CodecUtil; 23 | 24 | public class BidEncoder 25 | { 26 | public static final int BLOCK_LENGTH = 20; 27 | public static final int TEMPLATE_ID = 2; 28 | public static final int SCHEMA_ID = 1; 29 | public static final int SCHEMA_VERSION = 0; 30 | 31 | private final BidEncoder parentMessage = this; 32 | private MutableDirectBuffer buffer; 33 | protected int offset; 34 | protected int limit; 35 | protected int actingBlockLength; 36 | protected int actingVersion; 37 | 38 | public int sbeBlockLength() 39 | { 40 | return BLOCK_LENGTH; 41 | } 42 | 43 | public int sbeTemplateId() 44 | { 45 | return TEMPLATE_ID; 46 | } 47 | 48 | public int sbeSchemaId() 49 | { 50 | return SCHEMA_ID; 51 | } 52 | 53 | public int sbeSchemaVersion() 54 | { 55 | return SCHEMA_VERSION; 56 | } 57 | 58 | public String sbeSemanticType() 59 | { 60 | return ""; 61 | } 62 | 63 | public int offset() 64 | { 65 | return offset; 66 | } 67 | 68 | public BidEncoder wrap(final MutableDirectBuffer buffer, final int offset) 69 | { 70 | this.buffer = buffer; 71 | this.offset = offset; 72 | limit(offset + BLOCK_LENGTH); 73 | return this; 74 | } 75 | 76 | public int size() 77 | { 78 | return limit - offset; 79 | } 80 | 81 | public int limit() 82 | { 83 | return limit; 84 | } 85 | 86 | public void limit(final int limit) 87 | { 88 | buffer.checkLimit(limit); 89 | this.limit = limit; 90 | } 91 | 92 | public static int auctionIdNullValue() 93 | { 94 | return -2147483648; 95 | } 96 | 97 | public static int auctionIdMinValue() 98 | { 99 | return -2147483647; 100 | } 101 | 102 | public static int auctionIdMaxValue() 103 | { 104 | return 2147483647; 105 | } 106 | public BidEncoder auctionId(final int value) 107 | { 108 | CodecUtil.int32Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 109 | return this; 110 | } 111 | 112 | public static long bidderIdNullValue() 113 | { 114 | return -9223372036854775808L; 115 | } 116 | 117 | public static long bidderIdMinValue() 118 | { 119 | return -9223372036854775807L; 120 | } 121 | 122 | public static long bidderIdMaxValue() 123 | { 124 | return 9223372036854775807L; 125 | } 126 | public BidEncoder bidderId(final long value) 127 | { 128 | CodecUtil.int64Put(buffer, offset + 4, value, java.nio.ByteOrder.LITTLE_ENDIAN); 129 | return this; 130 | } 131 | 132 | public static long valueNullValue() 133 | { 134 | return -9223372036854775808L; 135 | } 136 | 137 | public static long valueMinValue() 138 | { 139 | return -9223372036854775807L; 140 | } 141 | 142 | public static long valueMaxValue() 143 | { 144 | return 9223372036854775807L; 145 | } 146 | public BidEncoder value(final long value) 147 | { 148 | CodecUtil.int64Put(buffer, offset + 12, value, java.nio.ByteOrder.LITTLE_ENDIAN); 149 | return this; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /advanced-service/src/main/java/amaethon/generated/GroupSizeEncodingDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.agrona.DirectBuffer; 22 | import uk.co.real_logic.sbe.codec.java.CodecUtil; 23 | 24 | public class GroupSizeEncodingDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public GroupSizeEncodingDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 4; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | 58 | public int blockLength() 59 | { 60 | return CodecUtil.uint16Get(buffer, offset + 0, java.nio.ByteOrder.LITTLE_ENDIAN); 61 | } 62 | 63 | 64 | public static int numInGroupNullValue() 65 | { 66 | return 65535; 67 | } 68 | 69 | public static int numInGroupMinValue() 70 | { 71 | return 0; 72 | } 73 | 74 | public static int numInGroupMaxValue() 75 | { 76 | return 65534; 77 | } 78 | 79 | public int numInGroup() 80 | { 81 | return CodecUtil.uint16Get(buffer, offset + 2, java.nio.ByteOrder.LITTLE_ENDIAN); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /advanced-service/src/main/java/amaethon/generated/GroupSizeEncodingEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.agrona.MutableDirectBuffer; 22 | import uk.co.real_logic.sbe.codec.java.CodecUtil; 23 | 24 | public class GroupSizeEncodingEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public GroupSizeEncodingEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 4; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | public GroupSizeEncodingEncoder blockLength(final int value) 58 | { 59 | CodecUtil.uint16Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 60 | return this; 61 | } 62 | 63 | public static int numInGroupNullValue() 64 | { 65 | return 65535; 66 | } 67 | 68 | public static int numInGroupMinValue() 69 | { 70 | return 0; 71 | } 72 | 73 | public static int numInGroupMaxValue() 74 | { 75 | return 65534; 76 | } 77 | public GroupSizeEncodingEncoder numInGroup(final int value) 78 | { 79 | CodecUtil.uint16Put(buffer, offset + 2, value, java.nio.ByteOrder.LITTLE_ENDIAN); 80 | return this; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /advanced-service/src/main/java/amaethon/generated/MessageHeaderDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.agrona.DirectBuffer; 22 | import uk.co.real_logic.sbe.codec.java.CodecUtil; 23 | 24 | public class MessageHeaderDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public MessageHeaderDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 8; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | 58 | public int blockLength() 59 | { 60 | return CodecUtil.uint16Get(buffer, offset + 0, java.nio.ByteOrder.LITTLE_ENDIAN); 61 | } 62 | 63 | 64 | public static int templateIdNullValue() 65 | { 66 | return 65535; 67 | } 68 | 69 | public static int templateIdMinValue() 70 | { 71 | return 0; 72 | } 73 | 74 | public static int templateIdMaxValue() 75 | { 76 | return 65534; 77 | } 78 | 79 | public int templateId() 80 | { 81 | return CodecUtil.uint16Get(buffer, offset + 2, java.nio.ByteOrder.LITTLE_ENDIAN); 82 | } 83 | 84 | 85 | public static int schemaIdNullValue() 86 | { 87 | return 65535; 88 | } 89 | 90 | public static int schemaIdMinValue() 91 | { 92 | return 0; 93 | } 94 | 95 | public static int schemaIdMaxValue() 96 | { 97 | return 65534; 98 | } 99 | 100 | public int schemaId() 101 | { 102 | return CodecUtil.uint16Get(buffer, offset + 4, java.nio.ByteOrder.LITTLE_ENDIAN); 103 | } 104 | 105 | 106 | public static int versionNullValue() 107 | { 108 | return 65535; 109 | } 110 | 111 | public static int versionMinValue() 112 | { 113 | return 0; 114 | } 115 | 116 | public static int versionMaxValue() 117 | { 118 | return 65534; 119 | } 120 | 121 | public int version() 122 | { 123 | return CodecUtil.uint16Get(buffer, offset + 6, java.nio.ByteOrder.LITTLE_ENDIAN); 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /advanced-service/src/main/java/amaethon/generated/MessageHeaderEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.agrona.MutableDirectBuffer; 22 | import uk.co.real_logic.sbe.codec.java.CodecUtil; 23 | 24 | public class MessageHeaderEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public MessageHeaderEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 8; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | public MessageHeaderEncoder blockLength(final int value) 58 | { 59 | CodecUtil.uint16Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 60 | return this; 61 | } 62 | 63 | public static int templateIdNullValue() 64 | { 65 | return 65535; 66 | } 67 | 68 | public static int templateIdMinValue() 69 | { 70 | return 0; 71 | } 72 | 73 | public static int templateIdMaxValue() 74 | { 75 | return 65534; 76 | } 77 | public MessageHeaderEncoder templateId(final int value) 78 | { 79 | CodecUtil.uint16Put(buffer, offset + 2, value, java.nio.ByteOrder.LITTLE_ENDIAN); 80 | return this; 81 | } 82 | 83 | public static int schemaIdNullValue() 84 | { 85 | return 65535; 86 | } 87 | 88 | public static int schemaIdMinValue() 89 | { 90 | return 0; 91 | } 92 | 93 | public static int schemaIdMaxValue() 94 | { 95 | return 65534; 96 | } 97 | public MessageHeaderEncoder schemaId(final int value) 98 | { 99 | CodecUtil.uint16Put(buffer, offset + 4, value, java.nio.ByteOrder.LITTLE_ENDIAN); 100 | return this; 101 | } 102 | 103 | public static int versionNullValue() 104 | { 105 | return 65535; 106 | } 107 | 108 | public static int versionMinValue() 109 | { 110 | return 0; 111 | } 112 | 113 | public static int versionMaxValue() 114 | { 115 | return 65534; 116 | } 117 | public MessageHeaderEncoder version(final int value) 118 | { 119 | CodecUtil.uint16Put(buffer, offset + 6, value, java.nio.ByteOrder.LITTLE_ENDIAN); 120 | return this; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /advanced-service/src/main/java/amaethon/generated/MetaAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | public enum MetaAttribute 22 | { 23 | EPOCH, 24 | TIME_UNIT, 25 | SEMANTIC_TYPE 26 | } 27 | -------------------------------------------------------------------------------- /advanced-service/src/main/java/amaethon/generated/VarDataEncodingDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.agrona.DirectBuffer; 22 | import uk.co.real_logic.sbe.codec.java.CodecUtil; 23 | 24 | public class VarDataEncodingDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public VarDataEncodingDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return -1; 41 | } 42 | 43 | public static short lengthNullValue() 44 | { 45 | return (short)255; 46 | } 47 | 48 | public static short lengthMinValue() 49 | { 50 | return (short)0; 51 | } 52 | 53 | public static short lengthMaxValue() 54 | { 55 | return (short)254; 56 | } 57 | 58 | public short length() 59 | { 60 | return CodecUtil.uint8Get(buffer, offset + 0); 61 | } 62 | 63 | 64 | public static short varDataNullValue() 65 | { 66 | return (short)255; 67 | } 68 | 69 | public static short varDataMinValue() 70 | { 71 | return (short)0; 72 | } 73 | 74 | public static short varDataMaxValue() 75 | { 76 | return (short)254; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /advanced-service/src/main/java/amaethon/generated/VarDataEncodingEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.agrona.MutableDirectBuffer; 22 | import uk.co.real_logic.sbe.codec.java.CodecUtil; 23 | 24 | public class VarDataEncodingEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public VarDataEncodingEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return -1; 41 | } 42 | 43 | public static short lengthNullValue() 44 | { 45 | return (short)255; 46 | } 47 | 48 | public static short lengthMinValue() 49 | { 50 | return (short)0; 51 | } 52 | 53 | public static short lengthMaxValue() 54 | { 55 | return (short)254; 56 | } 57 | public VarDataEncodingEncoder length(final short value) 58 | { 59 | CodecUtil.uint8Put(buffer, offset + 0, value); 60 | return this; 61 | } 62 | 63 | public static short varDataNullValue() 64 | { 65 | return (short)255; 66 | } 67 | 68 | public static short varDataMinValue() 69 | { 70 | return (short)0; 71 | } 72 | 73 | public static short varDataMaxValue() 74 | { 75 | return (short)254; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /basic-service/src/main/java/amaethon/Auction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import java.util.concurrent.TimeUnit; 21 | 22 | /** 23 | * Encapsulation of an Auction. Instances will be re-used by {@link AuctionHouse}. 24 | */ 25 | public class Auction 26 | { 27 | private static final long LINGER_TIMEOUT_NANOS = TimeUnit.SECONDS.toNanos(10); 28 | 29 | /* 30 | * INACTIVE means Auction not valid 31 | * ACTIVE means Auction is accepting bids 32 | * OVER means Auction is over (Auction will linger for a period of time before being re-used) 33 | */ 34 | enum State 35 | { 36 | INACTIVE, ACTIVE, OVER 37 | } 38 | 39 | private byte[] nameInBytes = new byte[1024]; 40 | private int nameLength; 41 | private long expiration; 42 | private long currentHighBid; 43 | private long currentHighBidderId; 44 | private State state; 45 | 46 | public Auction() 47 | { 48 | this.state = State.INACTIVE; 49 | } 50 | 51 | public void reset(final byte[] name, final int nameLength, final long expiration, final long reserveValue) 52 | { 53 | System.arraycopy(name, 0, this.nameInBytes, 0, name.length); 54 | this.nameLength = nameLength; 55 | this.expiration = expiration; 56 | this.currentHighBid = reserveValue; 57 | this.currentHighBidderId = Bidder.INVALID_BIDDER; 58 | this.state = State.ACTIVE; 59 | } 60 | 61 | public boolean isInactive() 62 | { 63 | return (State.INACTIVE == state); 64 | } 65 | 66 | public String name() 67 | { 68 | return new String(nameInBytes, 0, nameLength); 69 | } 70 | 71 | public long highBid() 72 | { 73 | return currentHighBid; 74 | } 75 | 76 | public long highBidder() 77 | { 78 | return currentHighBidderId; 79 | } 80 | 81 | // return 0 for nothing new or >0 for activity 82 | public int onAdvanceTime(final long now) 83 | { 84 | int result = 0; 85 | 86 | if (State.ACTIVE == state && now > expiration) 87 | { 88 | state = State.OVER; 89 | result = 1; 90 | } 91 | else if (State.OVER == state && now > (expiration + LINGER_TIMEOUT_NANOS)) 92 | { 93 | state = State.INACTIVE; 94 | } 95 | 96 | return result; 97 | } 98 | 99 | // True if high bid. False if not. 100 | public boolean bid(final long bidderId, final long value) 101 | { 102 | boolean result = false; 103 | 104 | if (State.ACTIVE == state && value > currentHighBid) 105 | { 106 | currentHighBid = value; 107 | currentHighBidderId = bidderId; 108 | result = true; 109 | } 110 | 111 | return result; 112 | } 113 | 114 | public void cancel() 115 | { 116 | this.currentHighBidderId = Bidder.INVALID_BIDDER; 117 | this.state = State.OVER; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /basic-service/src/main/java/amaethon/AuctionService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import amaethon.generated.AuctionDecoder; 21 | import amaethon.generated.BidDecoder; 22 | import amaethon.generated.MessageHeaderDecoder; 23 | import uk.co.real_logic.aeron.Aeron; 24 | import uk.co.real_logic.aeron.Subscription; 25 | import uk.co.real_logic.aeron.logbuffer.FragmentHandler; 26 | import uk.co.real_logic.aeron.logbuffer.Header; 27 | import uk.co.real_logic.agrona.CloseHelper; 28 | import uk.co.real_logic.agrona.DirectBuffer; 29 | import uk.co.real_logic.agrona.concurrent.BackoffIdleStrategy; 30 | import uk.co.real_logic.agrona.concurrent.IdleStrategy; 31 | 32 | import java.util.concurrent.TimeUnit; 33 | 34 | public class AuctionService implements Runnable, AutoCloseable, FragmentHandler 35 | { 36 | private static final int MESSAGE_TEMPLATE_VERSION = 0; 37 | private static final long IDLE_MAX_SPINS = 0; 38 | private static final long IDLE_MAX_YIELDS = 0; 39 | private static final long IDLE_MIN_PARK_NS = TimeUnit.NANOSECONDS.toNanos(1); 40 | private static final long IDLE_MAX_PARK_NS = TimeUnit.MILLISECONDS.toNanos(1); 41 | 42 | private final MessageHeaderDecoder messageHeaderDecoder = new MessageHeaderDecoder(); 43 | private final AuctionDecoder auctionDecoder = new AuctionDecoder(); 44 | private final BidDecoder bidDecoder = new BidDecoder(); 45 | private final byte[] tmpByteArray = new byte[1024]; 46 | private final IdleStrategy idleStrategy = 47 | new BackoffIdleStrategy(IDLE_MAX_SPINS, IDLE_MAX_YIELDS, IDLE_MIN_PARK_NS, IDLE_MAX_PARK_NS); 48 | 49 | private final AuctionHouse house; 50 | private Aeron aeron; 51 | private Subscription subscription; 52 | 53 | private volatile boolean running = true; 54 | 55 | public AuctionService(final String submissionChannel, final int submissionStreamId) 56 | { 57 | house = new AuctionHouse( 58 | (auction) -> System.out.format("new auction: name=%s\n", auction.name()), 59 | (auction) -> System.out.format( 60 | "new high bid: name=%s, bidder=%d, bid=%d\n", auction.name(), auction.highBidder(), auction.highBid()), 61 | (auction) -> System.out.format( 62 | "auction won: name=%s, bidder=%d, bid=%d\n", auction.name(), auction.highBidder(), auction.highBid())); 63 | 64 | // TODO: 65 | } 66 | 67 | public AuctionHouse house() 68 | { 69 | return house; 70 | } 71 | 72 | public void shutdown() 73 | { 74 | running = false; 75 | } 76 | 77 | public void close() 78 | { 79 | CloseHelper.quietClose(subscription); 80 | CloseHelper.quietClose(aeron); 81 | } 82 | 83 | public void run() 84 | { 85 | while (running) 86 | { 87 | final int fragmentsRead = 0; // TODO: 88 | final long now = System.nanoTime(); 89 | 90 | house.advanceTime(now); 91 | 92 | idleStrategy.idle(fragmentsRead); 93 | } 94 | } 95 | 96 | public void onFragment(DirectBuffer buffer, int offset, int length, Header header) 97 | { 98 | // TODO: for exercise, handle data 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /basic-service/src/main/java/amaethon/Bidder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import java.util.Arrays; 21 | 22 | /** 23 | * Encapsulation of a bidder 24 | */ 25 | public class Bidder 26 | { 27 | public static final long INVALID_BIDDER = -1; 28 | 29 | private final byte[] name; 30 | private final long id; 31 | private long budget; 32 | 33 | public Bidder(final byte[] name, final long bidderId, final long budget) 34 | { 35 | this.name = Arrays.copyOf(name, name.length); 36 | this.id = bidderId; 37 | this.budget = budget; 38 | } 39 | 40 | public byte[] name() 41 | { 42 | return name; 43 | } 44 | 45 | public long id() 46 | { 47 | return id; 48 | } 49 | 50 | public long budget() 51 | { 52 | return budget; 53 | } 54 | 55 | public void decrementBudget(final long price) 56 | { 57 | budget -= price; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /basic-service/src/main/java/amaethon/Model.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import java.util.function.Consumer; 21 | 22 | /** 23 | * Interface for an Auction House 24 | */ 25 | public interface Model 26 | { 27 | // add an auction 28 | int add(final byte[] name, final int nameLength, final long expiration, final long reserveValue); 29 | 30 | // cancel an auction 31 | void cancel(final int auctionId); 32 | 33 | // bid on an auction. True if high bid, False if not 34 | boolean bid(final int auctionId, final long bidderId, final long value); 35 | 36 | // iterator over all non-inactive auctions (for activity feed and for advancing time on auctions) 37 | void forEach(final Consumer consumer); 38 | 39 | // done to add a new bidding account to the system 40 | void addBidder(final byte[] name, final long bidderId, final long budget); 41 | } -------------------------------------------------------------------------------- /basic-service/src/main/java/amaethon/RunExercise.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import uk.co.real_logic.aeron.driver.MediaDriver; 21 | 22 | /** 23 | * Runner for the exercise that has a contained Media Driver, AuctionService and AutomatedClient 24 | */ 25 | public class RunExercise 26 | { 27 | public static final String SUBMISSION_CHANNEL = "aeron:udp?remote=localhost:43456"; 28 | public static final int SUBMISSION_STREAM_ID = 1; 29 | 30 | public static void main(final String[] args) throws Exception 31 | { 32 | final MediaDriver.Context ctx = new MediaDriver.Context(); 33 | final MediaDriver mediaDriver = MediaDriver.launch(ctx.dirsDeleteOnStart(true)); 34 | final AuctionService service = new AuctionService(SUBMISSION_CHANNEL, SUBMISSION_STREAM_ID); 35 | final Thread serviceThread = new Thread(service); 36 | final AuctionHouse house = service.house(); 37 | 38 | serviceThread.setName("AuctionService"); 39 | serviceThread.start(); 40 | 41 | try (final AutomatedClient client = new AutomatedClient(SUBMISSION_CHANNEL, SUBMISSION_STREAM_ID)) 42 | { 43 | house.addBidder("tmontgomery".getBytes(), 1, 0); 44 | house.addBidder("mjpt777".getBytes(), 2, 0); 45 | house.addBidder("RichardWarburton".getBytes(), 3, 0); 46 | 47 | client.auction("Star Wars Force Awakens Pre-Pre-Release", 1000000000, "00:00:10"); 48 | client.bid(0, 1, 1000000000 + 1); 49 | client.auction("Issue #1000", 0, "00:00:05"); 50 | client.bid(1, 2, 1); 51 | client.bid(1, 3, 1); 52 | client.bid(1, 1, 2); 53 | 54 | Thread.sleep(11000); 55 | } 56 | 57 | service.shutdown(); 58 | serviceThread.join(); 59 | service.close(); 60 | mediaDriver.close(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /basic-service/src/main/java/amaethon/generated/BidEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.agrona.MutableDirectBuffer; 22 | import uk.co.real_logic.sbe.codec.java.CodecUtil; 23 | 24 | public class BidEncoder 25 | { 26 | public static final int BLOCK_LENGTH = 20; 27 | public static final int TEMPLATE_ID = 2; 28 | public static final int SCHEMA_ID = 1; 29 | public static final int SCHEMA_VERSION = 0; 30 | 31 | private final BidEncoder parentMessage = this; 32 | private MutableDirectBuffer buffer; 33 | protected int offset; 34 | protected int limit; 35 | protected int actingBlockLength; 36 | protected int actingVersion; 37 | 38 | public int sbeBlockLength() 39 | { 40 | return BLOCK_LENGTH; 41 | } 42 | 43 | public int sbeTemplateId() 44 | { 45 | return TEMPLATE_ID; 46 | } 47 | 48 | public int sbeSchemaId() 49 | { 50 | return SCHEMA_ID; 51 | } 52 | 53 | public int sbeSchemaVersion() 54 | { 55 | return SCHEMA_VERSION; 56 | } 57 | 58 | public String sbeSemanticType() 59 | { 60 | return ""; 61 | } 62 | 63 | public int offset() 64 | { 65 | return offset; 66 | } 67 | 68 | public BidEncoder wrap(final MutableDirectBuffer buffer, final int offset) 69 | { 70 | this.buffer = buffer; 71 | this.offset = offset; 72 | limit(offset + BLOCK_LENGTH); 73 | return this; 74 | } 75 | 76 | public int size() 77 | { 78 | return limit - offset; 79 | } 80 | 81 | public int limit() 82 | { 83 | return limit; 84 | } 85 | 86 | public void limit(final int limit) 87 | { 88 | buffer.checkLimit(limit); 89 | this.limit = limit; 90 | } 91 | 92 | public static int auctionIdNullValue() 93 | { 94 | return -2147483648; 95 | } 96 | 97 | public static int auctionIdMinValue() 98 | { 99 | return -2147483647; 100 | } 101 | 102 | public static int auctionIdMaxValue() 103 | { 104 | return 2147483647; 105 | } 106 | public BidEncoder auctionId(final int value) 107 | { 108 | CodecUtil.int32Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 109 | return this; 110 | } 111 | 112 | public static long bidderIdNullValue() 113 | { 114 | return -9223372036854775808L; 115 | } 116 | 117 | public static long bidderIdMinValue() 118 | { 119 | return -9223372036854775807L; 120 | } 121 | 122 | public static long bidderIdMaxValue() 123 | { 124 | return 9223372036854775807L; 125 | } 126 | public BidEncoder bidderId(final long value) 127 | { 128 | CodecUtil.int64Put(buffer, offset + 4, value, java.nio.ByteOrder.LITTLE_ENDIAN); 129 | return this; 130 | } 131 | 132 | public static long valueNullValue() 133 | { 134 | return -9223372036854775808L; 135 | } 136 | 137 | public static long valueMinValue() 138 | { 139 | return -9223372036854775807L; 140 | } 141 | 142 | public static long valueMaxValue() 143 | { 144 | return 9223372036854775807L; 145 | } 146 | public BidEncoder value(final long value) 147 | { 148 | CodecUtil.int64Put(buffer, offset + 12, value, java.nio.ByteOrder.LITTLE_ENDIAN); 149 | return this; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /basic-service/src/main/java/amaethon/generated/MessageHeaderDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.agrona.DirectBuffer; 22 | import uk.co.real_logic.sbe.codec.java.CodecUtil; 23 | 24 | public class MessageHeaderDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public MessageHeaderDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 8; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | 58 | public int blockLength() 59 | { 60 | return CodecUtil.uint16Get(buffer, offset + 0, java.nio.ByteOrder.LITTLE_ENDIAN); 61 | } 62 | 63 | 64 | public static int templateIdNullValue() 65 | { 66 | return 65535; 67 | } 68 | 69 | public static int templateIdMinValue() 70 | { 71 | return 0; 72 | } 73 | 74 | public static int templateIdMaxValue() 75 | { 76 | return 65534; 77 | } 78 | 79 | public int templateId() 80 | { 81 | return CodecUtil.uint16Get(buffer, offset + 2, java.nio.ByteOrder.LITTLE_ENDIAN); 82 | } 83 | 84 | 85 | public static int schemaIdNullValue() 86 | { 87 | return 65535; 88 | } 89 | 90 | public static int schemaIdMinValue() 91 | { 92 | return 0; 93 | } 94 | 95 | public static int schemaIdMaxValue() 96 | { 97 | return 65534; 98 | } 99 | 100 | public int schemaId() 101 | { 102 | return CodecUtil.uint16Get(buffer, offset + 4, java.nio.ByteOrder.LITTLE_ENDIAN); 103 | } 104 | 105 | 106 | public static int versionNullValue() 107 | { 108 | return 65535; 109 | } 110 | 111 | public static int versionMinValue() 112 | { 113 | return 0; 114 | } 115 | 116 | public static int versionMaxValue() 117 | { 118 | return 65534; 119 | } 120 | 121 | public int version() 122 | { 123 | return CodecUtil.uint16Get(buffer, offset + 6, java.nio.ByteOrder.LITTLE_ENDIAN); 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /basic-service/src/main/java/amaethon/generated/MessageHeaderEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.agrona.MutableDirectBuffer; 22 | import uk.co.real_logic.sbe.codec.java.CodecUtil; 23 | 24 | public class MessageHeaderEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public MessageHeaderEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 8; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | public MessageHeaderEncoder blockLength(final int value) 58 | { 59 | CodecUtil.uint16Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 60 | return this; 61 | } 62 | 63 | public static int templateIdNullValue() 64 | { 65 | return 65535; 66 | } 67 | 68 | public static int templateIdMinValue() 69 | { 70 | return 0; 71 | } 72 | 73 | public static int templateIdMaxValue() 74 | { 75 | return 65534; 76 | } 77 | public MessageHeaderEncoder templateId(final int value) 78 | { 79 | CodecUtil.uint16Put(buffer, offset + 2, value, java.nio.ByteOrder.LITTLE_ENDIAN); 80 | return this; 81 | } 82 | 83 | public static int schemaIdNullValue() 84 | { 85 | return 65535; 86 | } 87 | 88 | public static int schemaIdMinValue() 89 | { 90 | return 0; 91 | } 92 | 93 | public static int schemaIdMaxValue() 94 | { 95 | return 65534; 96 | } 97 | public MessageHeaderEncoder schemaId(final int value) 98 | { 99 | CodecUtil.uint16Put(buffer, offset + 4, value, java.nio.ByteOrder.LITTLE_ENDIAN); 100 | return this; 101 | } 102 | 103 | public static int versionNullValue() 104 | { 105 | return 65535; 106 | } 107 | 108 | public static int versionMinValue() 109 | { 110 | return 0; 111 | } 112 | 113 | public static int versionMaxValue() 114 | { 115 | return 65534; 116 | } 117 | public MessageHeaderEncoder version(final int value) 118 | { 119 | CodecUtil.uint16Put(buffer, offset + 6, value, java.nio.ByteOrder.LITTLE_ENDIAN); 120 | return this; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /basic-service/src/main/java/amaethon/generated/MetaAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | public enum MetaAttribute 22 | { 23 | EPOCH, 24 | TIME_UNIT, 25 | SEMANTIC_TYPE 26 | } 27 | -------------------------------------------------------------------------------- /basic-service/src/main/java/amaethon/generated/PriceDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.agrona.DirectBuffer; 22 | import uk.co.real_logic.sbe.codec.java.CodecUtil; 23 | 24 | public class PriceDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public PriceDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 9; 41 | } 42 | 43 | public static long mantissaNullValue() 44 | { 45 | return -9223372036854775808L; 46 | } 47 | 48 | public static long mantissaMinValue() 49 | { 50 | return -9223372036854775807L; 51 | } 52 | 53 | public static long mantissaMaxValue() 54 | { 55 | return 9223372036854775807L; 56 | } 57 | 58 | public long mantissa() 59 | { 60 | return CodecUtil.int64Get(buffer, offset + 0, java.nio.ByteOrder.LITTLE_ENDIAN); 61 | } 62 | 63 | 64 | public static byte exponentNullValue() 65 | { 66 | return (byte)-128; 67 | } 68 | 69 | public static byte exponentMinValue() 70 | { 71 | return (byte)-127; 72 | } 73 | 74 | public static byte exponentMaxValue() 75 | { 76 | return (byte)127; 77 | } 78 | 79 | public byte exponent() 80 | { 81 | return CodecUtil.int8Get(buffer, offset + 8); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /basic-service/src/main/java/amaethon/generated/PriceEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.agrona.MutableDirectBuffer; 22 | import uk.co.real_logic.sbe.codec.java.CodecUtil; 23 | 24 | public class PriceEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public PriceEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 9; 41 | } 42 | 43 | public static long mantissaNullValue() 44 | { 45 | return -9223372036854775808L; 46 | } 47 | 48 | public static long mantissaMinValue() 49 | { 50 | return -9223372036854775807L; 51 | } 52 | 53 | public static long mantissaMaxValue() 54 | { 55 | return 9223372036854775807L; 56 | } 57 | public PriceEncoder mantissa(final long value) 58 | { 59 | CodecUtil.int64Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 60 | return this; 61 | } 62 | 63 | public static byte exponentNullValue() 64 | { 65 | return (byte)-128; 66 | } 67 | 68 | public static byte exponentMinValue() 69 | { 70 | return (byte)-127; 71 | } 72 | 73 | public static byte exponentMaxValue() 74 | { 75 | return (byte)127; 76 | } 77 | public PriceEncoder exponent(final byte value) 78 | { 79 | CodecUtil.int8Put(buffer, offset + 8, value); 80 | return this; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /basic-service/src/main/java/amaethon/generated/VarDataEncodingDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.agrona.DirectBuffer; 22 | import uk.co.real_logic.sbe.codec.java.CodecUtil; 23 | 24 | public class VarDataEncodingDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public VarDataEncodingDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return -1; 41 | } 42 | 43 | public static short lengthNullValue() 44 | { 45 | return (short)255; 46 | } 47 | 48 | public static short lengthMinValue() 49 | { 50 | return (short)0; 51 | } 52 | 53 | public static short lengthMaxValue() 54 | { 55 | return (short)254; 56 | } 57 | 58 | public short length() 59 | { 60 | return CodecUtil.uint8Get(buffer, offset + 0); 61 | } 62 | 63 | 64 | public static short varDataNullValue() 65 | { 66 | return (short)255; 67 | } 68 | 69 | public static short varDataMinValue() 70 | { 71 | return (short)0; 72 | } 73 | 74 | public static short varDataMaxValue() 75 | { 76 | return (short)254; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /basic-service/src/main/java/amaethon/generated/VarDataEncodingEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.agrona.MutableDirectBuffer; 22 | import uk.co.real_logic.sbe.codec.java.CodecUtil; 23 | 24 | public class VarDataEncodingEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public VarDataEncodingEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return -1; 41 | } 42 | 43 | public static short lengthNullValue() 44 | { 45 | return (short)255; 46 | } 47 | 48 | public static short lengthMinValue() 49 | { 50 | return (short)0; 51 | } 52 | 53 | public static short lengthMaxValue() 54 | { 55 | return (short)254; 56 | } 57 | public VarDataEncodingEncoder length(final short value) 58 | { 59 | CodecUtil.uint8Put(buffer, offset + 0, value); 60 | return this; 61 | } 62 | 63 | public static short varDataNullValue() 64 | { 65 | return (short)255; 66 | } 67 | 68 | public static short varDataMinValue() 69 | { 70 | return (short)0; 71 | } 72 | 73 | public static short varDataMaxValue() 74 | { 75 | return (short)254; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /basic-service/src/main/resources/Amaethon-schema.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | defaultTasks 'clean', 'build' 19 | 20 | buildscript { 21 | repositories { 22 | maven { 23 | url 'https://plugins.gradle.org/m2/' 24 | } 25 | } 26 | dependencies { 27 | classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.2' 28 | } 29 | } 30 | 31 | subprojects { 32 | apply plugin: 'java' 33 | apply plugin: 'com.github.johnrengelman.shadow' 34 | 35 | sourceCompatibility = 1.8 36 | targetCompatibility = 1.8 37 | 38 | repositories { 39 | mavenCentral() 40 | mavenLocal() 41 | } 42 | 43 | dependencies { 44 | compile 'uk.co.real-logic:aeron-all:0.2.2', 45 | 'uk.co.real-logic:sbe:1.1.7-RC2' 46 | } 47 | 48 | build.doLast { 49 | tasks.shadowJar.execute() 50 | } 51 | 52 | task(generateCodecs, type: JavaExec) { 53 | description = "Generate SBE codecs into ${project.projectDir}/src/main/java/amaethon/generated" 54 | main = 'uk.co.real_logic.sbe.SbeTool' 55 | systemProperties( 56 | 'sbe.output.dir': "${project.projectDir}/src/main/java", 57 | 'sbe.target.language': 'Java', 58 | 'sbe.validation.stop.on.error': 'true', 59 | 'sbe.validation.xsd': "${project.projectDir}/src/main/resources/fpl/SimpleBinary1-0.xsd") 60 | args "${project.projectDir}/src/main/resources/Amaethon-schema.xml" 61 | } 62 | 63 | task(run, type: JavaExec) { 64 | description = "Run exercise" 65 | main = 'amaethon.RunExercise' 66 | classpath = sourceSets.main.runtimeClasspath 67 | } 68 | } 69 | 70 | task wrapper(type: Wrapper) { 71 | gradleVersion = '2.9' 72 | } 73 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015 Real Logic Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # 17 | 18 | org.gradle.daemon=true 19 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmontgomery/Amaethon/b9de5a2e4ef321c506dc87ce8c4aa0bb3c30a848/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Dec 03 15:12:47 GMT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | include 'basic-service', 'activity-feed', 'advanced-service', 'solutions:basic-service', 'solutions:activity-feed', 'solutions:advanced-service' -------------------------------------------------------------------------------- /solutions/activity-feed/src/main/java/amaethon/Auction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import java.util.concurrent.TimeUnit; 21 | 22 | /** 23 | * Encapsulation of an Auction. Instances will be re-used by {@link AuctionHouse}. 24 | */ 25 | public class Auction 26 | { 27 | private static final long LINGER_TIMEOUT_NANOS = TimeUnit.SECONDS.toNanos(10); 28 | 29 | /* 30 | * INACTIVE means Auction not valid 31 | * ACTIVE means Auction is accepting bids 32 | * OVER means Auction is over (Auction will linger for a period of time before being re-used) 33 | */ 34 | enum State 35 | { 36 | INACTIVE, ACTIVE, OVER 37 | } 38 | 39 | private byte[] nameInBytes = new byte[1024]; 40 | private int nameLength; 41 | private int id; 42 | private long expiration; 43 | private long currentHighBid; 44 | private long currentHighBidderId; 45 | private State state; 46 | 47 | public Auction() 48 | { 49 | this.state = State.INACTIVE; 50 | } 51 | 52 | public void reset(final int id, final byte[] name, final int nameLength, final long expiration, final long reserveValue) 53 | { 54 | this.id = id; 55 | System.arraycopy(name, 0, this.nameInBytes, 0, name.length); 56 | this.nameLength = nameLength; 57 | this.expiration = expiration; 58 | this.currentHighBid = reserveValue; 59 | this.currentHighBidderId = Bidder.INVALID_BIDDER; 60 | this.state = State.ACTIVE; 61 | } 62 | 63 | public boolean isInactive() 64 | { 65 | return (State.INACTIVE == state); 66 | } 67 | 68 | public boolean isActive() 69 | { 70 | return (State.ACTIVE == state); 71 | } 72 | 73 | public int id() 74 | { 75 | return id; 76 | } 77 | 78 | public String name() 79 | { 80 | return new String(nameInBytes, 0, nameLength); 81 | } 82 | 83 | public byte[] nameInBytes() 84 | { 85 | return nameInBytes; 86 | } 87 | 88 | public int nameLength() 89 | { 90 | return nameLength; 91 | } 92 | 93 | public long expiration() 94 | { 95 | return expiration; 96 | } 97 | 98 | public long highBid() 99 | { 100 | return currentHighBid; 101 | } 102 | 103 | public long highBidder() 104 | { 105 | return currentHighBidderId; 106 | } 107 | 108 | // return 0 for nothing new or > 0 for activity 109 | public int onAdvanceTime(final long now) 110 | { 111 | int result = 0; 112 | 113 | if (State.ACTIVE == state && now > expiration) 114 | { 115 | state = State.OVER; 116 | result = 1; 117 | } 118 | else if (State.OVER == state && now > (expiration + LINGER_TIMEOUT_NANOS)) 119 | { 120 | state = State.INACTIVE; 121 | } 122 | 123 | return result; 124 | } 125 | 126 | // True if high bid. False if not. 127 | public boolean bid(final long bidderId, final long value) 128 | { 129 | boolean result = false; 130 | 131 | if (State.ACTIVE == state && value > currentHighBid) 132 | { 133 | currentHighBid = value; 134 | currentHighBidderId = bidderId; 135 | result = true; 136 | } 137 | 138 | return result; 139 | } 140 | 141 | public void cancel() 142 | { 143 | this.currentHighBidderId = Bidder.INVALID_BIDDER; 144 | this.state = State.OVER; 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /solutions/activity-feed/src/main/java/amaethon/Bidder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import java.util.Arrays; 21 | 22 | /** 23 | * Encapsulation of a bidder 24 | */ 25 | public class Bidder 26 | { 27 | public static final long INVALID_BIDDER = -1; 28 | 29 | private final byte[] name; 30 | private final long id; 31 | private long budget; 32 | 33 | public Bidder(final byte[] name, final long bidderId, final long budget) 34 | { 35 | this.name = Arrays.copyOf(name, name.length); 36 | this.id = bidderId; 37 | this.budget = budget; 38 | } 39 | 40 | public byte[] name() 41 | { 42 | return name; 43 | } 44 | 45 | public long id() 46 | { 47 | return id; 48 | } 49 | 50 | public long budget() 51 | { 52 | return budget; 53 | } 54 | 55 | public void decrementBudget(final long price) 56 | { 57 | budget -= price; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /solutions/activity-feed/src/main/java/amaethon/Model.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import java.util.function.Consumer; 21 | 22 | /** 23 | * Interface for an Auction House 24 | */ 25 | public interface Model 26 | { 27 | // add an auction 28 | int add(final byte[] name, final int nameLength, final long expiration, final long reserveValue); 29 | 30 | // cancel an auction 31 | void cancel(final int auctionId); 32 | 33 | // bid on an auction. True if high bid, False if not 34 | boolean bid(final int auctionId, final long bidderId, final long value); 35 | 36 | // iterator over all non-inactive auctions (for activity feed and for advancing time on auctions) 37 | void forEach(final Consumer consumer); 38 | 39 | // done to add a new bidding account to the system 40 | void addBidder(final byte[] name, final long bidderId, final long budget); 41 | } -------------------------------------------------------------------------------- /solutions/activity-feed/src/main/java/amaethon/RunExercise.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import uk.co.real_logic.aeron.driver.MediaDriver; 21 | 22 | import java.util.concurrent.TimeUnit; 23 | import java.util.concurrent.locks.LockSupport; 24 | 25 | /** 26 | * Runner for the exercise that has a contained Media Driver, AuctionService and AutomatedClient 27 | */ 28 | public class RunExercise 29 | { 30 | public static final String SUBMISSION_CHANNEL = "aeron:udp?remote=localhost:43456"; 31 | public static final int SUBMISSION_STREAM_ID = 1; 32 | public static final String ACTIVITY_FEED_CHANNEL = "aeron:udp?remote=localhost:43457"; // could be multicast 33 | public static final int ACTIVITY_FEED_STREAM_ID = 1; 34 | 35 | public static void main(final String[] args) throws Exception 36 | { 37 | final MediaDriver.Context ctx = new MediaDriver.Context(); 38 | final MediaDriver mediaDriver = MediaDriver.launch(ctx.dirsDeleteOnStart(true)); 39 | final AuctionService service = 40 | new AuctionService(SUBMISSION_CHANNEL, SUBMISSION_STREAM_ID, ACTIVITY_FEED_CHANNEL, ACTIVITY_FEED_STREAM_ID); 41 | final Thread serviceThread = new Thread(service); 42 | final AuctionHouse house = service.house(); 43 | 44 | serviceThread.setName("AuctionService"); 45 | serviceThread.start(); 46 | 47 | try (final AutomatedClient client = new AutomatedClient( 48 | SUBMISSION_CHANNEL, SUBMISSION_STREAM_ID, ACTIVITY_FEED_CHANNEL, ACTIVITY_FEED_STREAM_ID)) 49 | { 50 | house.addBidder("tmontgomery".getBytes(), 1, 0); 51 | house.addBidder("mjpt777".getBytes(), 2, 0); 52 | house.addBidder("RichardWarburton".getBytes(), 3, 0); 53 | 54 | client.auction("Star Wars Force Awakens Pre-Pre-Release", 1000000000, "00:00:10"); 55 | client.bid(0, 1, 1000000000 + 1); 56 | client.auction("Issue #1000", 0, "00:00:05"); 57 | client.bid(1, 2, 1); 58 | client.bid(1, 3, 1); 59 | client.bid(1, 1, 2); 60 | 61 | final long now = System.nanoTime(); 62 | final long end = now + TimeUnit.SECONDS.toNanos(15); 63 | 64 | while (System.nanoTime() < end) 65 | { 66 | client.pollActivityFeed(); 67 | LockSupport.parkNanos(TimeUnit.MICROSECONDS.toNanos(50)); 68 | } 69 | } 70 | 71 | service.shutdown(); 72 | serviceThread.join(); 73 | service.close(); 74 | mediaDriver.close(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /solutions/activity-feed/src/main/java/amaethon/generated/AuctionOverEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class AuctionOverEncoder 25 | { 26 | public static final int BLOCK_LENGTH = 20; 27 | public static final int TEMPLATE_ID = 5; 28 | public static final int SCHEMA_ID = 1; 29 | public static final int SCHEMA_VERSION = 0; 30 | 31 | private final AuctionOverEncoder parentMessage = this; 32 | private MutableDirectBuffer buffer; 33 | protected int offset; 34 | protected int limit; 35 | protected int actingBlockLength; 36 | protected int actingVersion; 37 | 38 | public int sbeBlockLength() 39 | { 40 | return BLOCK_LENGTH; 41 | } 42 | 43 | public int sbeTemplateId() 44 | { 45 | return TEMPLATE_ID; 46 | } 47 | 48 | public int sbeSchemaId() 49 | { 50 | return SCHEMA_ID; 51 | } 52 | 53 | public int sbeSchemaVersion() 54 | { 55 | return SCHEMA_VERSION; 56 | } 57 | 58 | public String sbeSemanticType() 59 | { 60 | return ""; 61 | } 62 | 63 | public int offset() 64 | { 65 | return offset; 66 | } 67 | 68 | public AuctionOverEncoder wrap(final MutableDirectBuffer buffer, final int offset) 69 | { 70 | this.buffer = buffer; 71 | this.offset = offset; 72 | limit(offset + BLOCK_LENGTH); 73 | return this; 74 | } 75 | 76 | public int size() 77 | { 78 | return limit - offset; 79 | } 80 | 81 | public int limit() 82 | { 83 | return limit; 84 | } 85 | 86 | public void limit(final int limit) 87 | { 88 | buffer.checkLimit(limit); 89 | this.limit = limit; 90 | } 91 | 92 | public static int auctionIdNullValue() 93 | { 94 | return -2147483648; 95 | } 96 | 97 | public static int auctionIdMinValue() 98 | { 99 | return -2147483647; 100 | } 101 | 102 | public static int auctionIdMaxValue() 103 | { 104 | return 2147483647; 105 | } 106 | public AuctionOverEncoder auctionId(final int value) 107 | { 108 | CodecUtil.int32Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 109 | return this; 110 | } 111 | 112 | public static long winningBidderIdNullValue() 113 | { 114 | return -9223372036854775808L; 115 | } 116 | 117 | public static long winningBidderIdMinValue() 118 | { 119 | return -9223372036854775807L; 120 | } 121 | 122 | public static long winningBidderIdMaxValue() 123 | { 124 | return 9223372036854775807L; 125 | } 126 | public AuctionOverEncoder winningBidderId(final long value) 127 | { 128 | CodecUtil.int64Put(buffer, offset + 4, value, java.nio.ByteOrder.LITTLE_ENDIAN); 129 | return this; 130 | } 131 | 132 | public static long winningBidNullValue() 133 | { 134 | return -9223372036854775808L; 135 | } 136 | 137 | public static long winningBidMinValue() 138 | { 139 | return -9223372036854775807L; 140 | } 141 | 142 | public static long winningBidMaxValue() 143 | { 144 | return 9223372036854775807L; 145 | } 146 | public AuctionOverEncoder winningBid(final long value) 147 | { 148 | CodecUtil.int64Put(buffer, offset + 12, value, java.nio.ByteOrder.LITTLE_ENDIAN); 149 | return this; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /solutions/activity-feed/src/main/java/amaethon/generated/BidEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class BidEncoder 25 | { 26 | public static final int BLOCK_LENGTH = 20; 27 | public static final int TEMPLATE_ID = 2; 28 | public static final int SCHEMA_ID = 1; 29 | public static final int SCHEMA_VERSION = 0; 30 | 31 | private final BidEncoder parentMessage = this; 32 | private MutableDirectBuffer buffer; 33 | protected int offset; 34 | protected int limit; 35 | protected int actingBlockLength; 36 | protected int actingVersion; 37 | 38 | public int sbeBlockLength() 39 | { 40 | return BLOCK_LENGTH; 41 | } 42 | 43 | public int sbeTemplateId() 44 | { 45 | return TEMPLATE_ID; 46 | } 47 | 48 | public int sbeSchemaId() 49 | { 50 | return SCHEMA_ID; 51 | } 52 | 53 | public int sbeSchemaVersion() 54 | { 55 | return SCHEMA_VERSION; 56 | } 57 | 58 | public String sbeSemanticType() 59 | { 60 | return ""; 61 | } 62 | 63 | public int offset() 64 | { 65 | return offset; 66 | } 67 | 68 | public BidEncoder wrap(final MutableDirectBuffer buffer, final int offset) 69 | { 70 | this.buffer = buffer; 71 | this.offset = offset; 72 | limit(offset + BLOCK_LENGTH); 73 | return this; 74 | } 75 | 76 | public int size() 77 | { 78 | return limit - offset; 79 | } 80 | 81 | public int limit() 82 | { 83 | return limit; 84 | } 85 | 86 | public void limit(final int limit) 87 | { 88 | buffer.checkLimit(limit); 89 | this.limit = limit; 90 | } 91 | 92 | public static int auctionIdNullValue() 93 | { 94 | return -2147483648; 95 | } 96 | 97 | public static int auctionIdMinValue() 98 | { 99 | return -2147483647; 100 | } 101 | 102 | public static int auctionIdMaxValue() 103 | { 104 | return 2147483647; 105 | } 106 | public BidEncoder auctionId(final int value) 107 | { 108 | CodecUtil.int32Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 109 | return this; 110 | } 111 | 112 | public static long bidderIdNullValue() 113 | { 114 | return -9223372036854775808L; 115 | } 116 | 117 | public static long bidderIdMinValue() 118 | { 119 | return -9223372036854775807L; 120 | } 121 | 122 | public static long bidderIdMaxValue() 123 | { 124 | return 9223372036854775807L; 125 | } 126 | public BidEncoder bidderId(final long value) 127 | { 128 | CodecUtil.int64Put(buffer, offset + 4, value, java.nio.ByteOrder.LITTLE_ENDIAN); 129 | return this; 130 | } 131 | 132 | public static long valueNullValue() 133 | { 134 | return -9223372036854775808L; 135 | } 136 | 137 | public static long valueMinValue() 138 | { 139 | return -9223372036854775807L; 140 | } 141 | 142 | public static long valueMaxValue() 143 | { 144 | return 9223372036854775807L; 145 | } 146 | public BidEncoder value(final long value) 147 | { 148 | CodecUtil.int64Put(buffer, offset + 12, value, java.nio.ByteOrder.LITTLE_ENDIAN); 149 | return this; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /solutions/activity-feed/src/main/java/amaethon/generated/GroupSizeEncodingDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.DirectBuffer; 23 | 24 | public class GroupSizeEncodingDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public GroupSizeEncodingDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 4; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | 58 | public int blockLength() 59 | { 60 | return CodecUtil.uint16Get(buffer, offset + 0, java.nio.ByteOrder.LITTLE_ENDIAN); 61 | } 62 | 63 | 64 | public static int numInGroupNullValue() 65 | { 66 | return 65535; 67 | } 68 | 69 | public static int numInGroupMinValue() 70 | { 71 | return 0; 72 | } 73 | 74 | public static int numInGroupMaxValue() 75 | { 76 | return 65534; 77 | } 78 | 79 | public int numInGroup() 80 | { 81 | return CodecUtil.uint16Get(buffer, offset + 2, java.nio.ByteOrder.LITTLE_ENDIAN); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /solutions/activity-feed/src/main/java/amaethon/generated/GroupSizeEncodingEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class GroupSizeEncodingEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public GroupSizeEncodingEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 4; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | public GroupSizeEncodingEncoder blockLength(final int value) 58 | { 59 | CodecUtil.uint16Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 60 | return this; 61 | } 62 | 63 | public static int numInGroupNullValue() 64 | { 65 | return 65535; 66 | } 67 | 68 | public static int numInGroupMinValue() 69 | { 70 | return 0; 71 | } 72 | 73 | public static int numInGroupMaxValue() 74 | { 75 | return 65534; 76 | } 77 | public GroupSizeEncodingEncoder numInGroup(final int value) 78 | { 79 | CodecUtil.uint16Put(buffer, offset + 2, value, java.nio.ByteOrder.LITTLE_ENDIAN); 80 | return this; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /solutions/activity-feed/src/main/java/amaethon/generated/MessageHeaderDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.DirectBuffer; 23 | 24 | public class MessageHeaderDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public MessageHeaderDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 8; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | 58 | public int blockLength() 59 | { 60 | return CodecUtil.uint16Get(buffer, offset + 0, java.nio.ByteOrder.LITTLE_ENDIAN); 61 | } 62 | 63 | 64 | public static int templateIdNullValue() 65 | { 66 | return 65535; 67 | } 68 | 69 | public static int templateIdMinValue() 70 | { 71 | return 0; 72 | } 73 | 74 | public static int templateIdMaxValue() 75 | { 76 | return 65534; 77 | } 78 | 79 | public int templateId() 80 | { 81 | return CodecUtil.uint16Get(buffer, offset + 2, java.nio.ByteOrder.LITTLE_ENDIAN); 82 | } 83 | 84 | 85 | public static int schemaIdNullValue() 86 | { 87 | return 65535; 88 | } 89 | 90 | public static int schemaIdMinValue() 91 | { 92 | return 0; 93 | } 94 | 95 | public static int schemaIdMaxValue() 96 | { 97 | return 65534; 98 | } 99 | 100 | public int schemaId() 101 | { 102 | return CodecUtil.uint16Get(buffer, offset + 4, java.nio.ByteOrder.LITTLE_ENDIAN); 103 | } 104 | 105 | 106 | public static int versionNullValue() 107 | { 108 | return 65535; 109 | } 110 | 111 | public static int versionMinValue() 112 | { 113 | return 0; 114 | } 115 | 116 | public static int versionMaxValue() 117 | { 118 | return 65534; 119 | } 120 | 121 | public int version() 122 | { 123 | return CodecUtil.uint16Get(buffer, offset + 6, java.nio.ByteOrder.LITTLE_ENDIAN); 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /solutions/activity-feed/src/main/java/amaethon/generated/MessageHeaderEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class MessageHeaderEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public MessageHeaderEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 8; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | public MessageHeaderEncoder blockLength(final int value) 58 | { 59 | CodecUtil.uint16Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 60 | return this; 61 | } 62 | 63 | public static int templateIdNullValue() 64 | { 65 | return 65535; 66 | } 67 | 68 | public static int templateIdMinValue() 69 | { 70 | return 0; 71 | } 72 | 73 | public static int templateIdMaxValue() 74 | { 75 | return 65534; 76 | } 77 | public MessageHeaderEncoder templateId(final int value) 78 | { 79 | CodecUtil.uint16Put(buffer, offset + 2, value, java.nio.ByteOrder.LITTLE_ENDIAN); 80 | return this; 81 | } 82 | 83 | public static int schemaIdNullValue() 84 | { 85 | return 65535; 86 | } 87 | 88 | public static int schemaIdMinValue() 89 | { 90 | return 0; 91 | } 92 | 93 | public static int schemaIdMaxValue() 94 | { 95 | return 65534; 96 | } 97 | public MessageHeaderEncoder schemaId(final int value) 98 | { 99 | CodecUtil.uint16Put(buffer, offset + 4, value, java.nio.ByteOrder.LITTLE_ENDIAN); 100 | return this; 101 | } 102 | 103 | public static int versionNullValue() 104 | { 105 | return 65535; 106 | } 107 | 108 | public static int versionMinValue() 109 | { 110 | return 0; 111 | } 112 | 113 | public static int versionMaxValue() 114 | { 115 | return 65534; 116 | } 117 | public MessageHeaderEncoder version(final int value) 118 | { 119 | CodecUtil.uint16Put(buffer, offset + 6, value, java.nio.ByteOrder.LITTLE_ENDIAN); 120 | return this; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /solutions/activity-feed/src/main/java/amaethon/generated/MetaAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | public enum MetaAttribute 22 | { 23 | EPOCH, 24 | TIME_UNIT, 25 | SEMANTIC_TYPE 26 | } 27 | -------------------------------------------------------------------------------- /solutions/activity-feed/src/main/java/amaethon/generated/VarDataEncodingDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.DirectBuffer; 23 | 24 | public class VarDataEncodingDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public VarDataEncodingDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return -1; 41 | } 42 | 43 | public static short lengthNullValue() 44 | { 45 | return (short)255; 46 | } 47 | 48 | public static short lengthMinValue() 49 | { 50 | return (short)0; 51 | } 52 | 53 | public static short lengthMaxValue() 54 | { 55 | return (short)254; 56 | } 57 | 58 | public short length() 59 | { 60 | return CodecUtil.uint8Get(buffer, offset + 0); 61 | } 62 | 63 | 64 | public static short varDataNullValue() 65 | { 66 | return (short)255; 67 | } 68 | 69 | public static short varDataMinValue() 70 | { 71 | return (short)0; 72 | } 73 | 74 | public static short varDataMaxValue() 75 | { 76 | return (short)254; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /solutions/activity-feed/src/main/java/amaethon/generated/VarDataEncodingEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class VarDataEncodingEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public VarDataEncodingEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return -1; 41 | } 42 | 43 | public static short lengthNullValue() 44 | { 45 | return (short)255; 46 | } 47 | 48 | public static short lengthMinValue() 49 | { 50 | return (short)0; 51 | } 52 | 53 | public static short lengthMaxValue() 54 | { 55 | return (short)254; 56 | } 57 | public VarDataEncodingEncoder length(final short value) 58 | { 59 | CodecUtil.uint8Put(buffer, offset + 0, value); 60 | return this; 61 | } 62 | 63 | public static short varDataNullValue() 64 | { 65 | return (short)255; 66 | } 67 | 68 | public static short varDataMinValue() 69 | { 70 | return (short)0; 71 | } 72 | 73 | public static short varDataMaxValue() 74 | { 75 | return (short)254; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /solutions/activity-feed/src/main/resources/Amaethon-schema.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /solutions/advanced-service/src/main/java/amaethon/Bidder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import java.util.Arrays; 21 | 22 | /** 23 | * Encapsulation of a bidder 24 | */ 25 | public class Bidder 26 | { 27 | public static final long INVALID_BIDDER = -1; 28 | 29 | private final byte[] name; 30 | private final long id; 31 | private long budget; 32 | 33 | public Bidder(final byte[] name, final long bidderId, final long budget) 34 | { 35 | this.name = Arrays.copyOf(name, name.length); 36 | this.id = bidderId; 37 | this.budget = budget; 38 | } 39 | 40 | public byte[] name() 41 | { 42 | return name; 43 | } 44 | 45 | public long id() 46 | { 47 | return id; 48 | } 49 | 50 | public long budget() 51 | { 52 | return budget; 53 | } 54 | 55 | public void decrementBudget(final long price) 56 | { 57 | budget -= price; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /solutions/advanced-service/src/main/java/amaethon/Model.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import java.util.function.Consumer; 21 | 22 | /** 23 | * Interface for an Auction House 24 | */ 25 | public interface Model 26 | { 27 | // add an auction 28 | int add(final byte[] name, final int nameLength, final long expiration, final long reserveValue); 29 | // exercise 3: add a new auction type 30 | int add(final byte[] name, final int nameLength, final long expiration, final long price, final int quantity); 31 | 32 | // cancel an auction 33 | void cancel(final int auctionId); 34 | 35 | // bid on an auction. True if high bid, False if not 36 | boolean bid(final int auctionId, final long bidderId, final long value); 37 | 38 | // iterator over all non-inactive auctions (for activity feed and for advancing time on auctions) 39 | void forEach(final Consumer consumer); 40 | 41 | // done to add a new bidding account to the system 42 | void addBidder(final byte[] name, final long bidderId, final long budget); 43 | } -------------------------------------------------------------------------------- /solutions/advanced-service/src/main/java/amaethon/RunExercise.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import uk.co.real_logic.aeron.driver.MediaDriver; 21 | 22 | import java.util.concurrent.TimeUnit; 23 | import java.util.concurrent.locks.LockSupport; 24 | 25 | /** 26 | * Runner for the exercise that has a contained Media Driver, AuctionService and AutomatedClient 27 | */ 28 | public class RunExercise 29 | { 30 | public static final String SUBMISSION_CHANNEL = "aeron:udp?remote=localhost:43456"; 31 | public static final int SUBMISSION_STREAM_ID = 1; 32 | public static final String ACTIVITY_FEED_CHANNEL = "aeron:udp?remote=localhost:43457"; // could be multicast 33 | public static final int ACTIVITY_FEED_STREAM_ID = 1; 34 | 35 | public static void main(final String[] args) throws Exception 36 | { 37 | final MediaDriver.Context ctx = new MediaDriver.Context(); 38 | final MediaDriver mediaDriver = MediaDriver.launch(ctx.dirsDeleteOnStart(true)); 39 | final AuctionService service = 40 | new AuctionService(SUBMISSION_CHANNEL, SUBMISSION_STREAM_ID, ACTIVITY_FEED_CHANNEL, ACTIVITY_FEED_STREAM_ID); 41 | final Thread serviceThread = new Thread(service); 42 | final AuctionHouse house = service.house(); 43 | 44 | serviceThread.setName("AuctionService"); 45 | serviceThread.start(); 46 | 47 | try (final AutomatedClient client = 48 | new AutomatedClient(SUBMISSION_CHANNEL, SUBMISSION_STREAM_ID, ACTIVITY_FEED_CHANNEL, ACTIVITY_FEED_STREAM_ID)) 49 | { 50 | house.addBidder("tmontgomery".getBytes(), 1, 0); 51 | house.addBidder("mjpt777".getBytes(), 2, 0); 52 | house.addBidder("RichardWarburton".getBytes(), 3, 0); 53 | 54 | client.auction("Star Wars Force Awakens Pre-Pre-Release", 1000000000, "00:00:10"); 55 | client.bid(0, 1, 1000000000 + 1); 56 | client.auction("Issue #1000", 0, "00:00:05"); 57 | client.auction("Fox Force Member", 10000, 5, "00:00:07"); 58 | client.bid(1, 2, 1); 59 | client.bid(1, 3, 1); 60 | client.bid(2, 2, 10000); 61 | client.bid(1, 1, 2); 62 | client.bid(2, 2, 10000); 63 | client.bid(2, 3, 10000); 64 | client.bid(2, 3, 10000); 65 | client.bid(2, 1, 10000); 66 | 67 | final long now = System.nanoTime(); 68 | final long end = now + TimeUnit.SECONDS.toNanos(15); 69 | 70 | while (System.nanoTime() < end) 71 | { 72 | client.pollActivityFeed(); 73 | LockSupport.parkNanos(TimeUnit.MICROSECONDS.toNanos(50)); 74 | } 75 | } 76 | 77 | service.shutdown(); 78 | serviceThread.join(); 79 | service.close(); 80 | mediaDriver.close(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /solutions/advanced-service/src/main/java/amaethon/generated/AuctionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | public enum AuctionType 22 | { 23 | Basic((byte)0), 24 | FixedPrice((byte)1), 25 | NULL_VAL((byte)-128); 26 | 27 | private final byte value; 28 | 29 | AuctionType(final byte value) 30 | { 31 | this.value = value; 32 | } 33 | 34 | public byte value() 35 | { 36 | return value; 37 | } 38 | 39 | public static AuctionType get(final byte value) 40 | { 41 | switch (value) 42 | { 43 | case 0: return Basic; 44 | case 1: return FixedPrice; 45 | } 46 | 47 | if ((byte)-128 == value) 48 | { 49 | return NULL_VAL; 50 | } 51 | 52 | throw new IllegalArgumentException("Unknown value: " + value); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /solutions/advanced-service/src/main/java/amaethon/generated/BidEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class BidEncoder 25 | { 26 | public static final int BLOCK_LENGTH = 20; 27 | public static final int TEMPLATE_ID = 2; 28 | public static final int SCHEMA_ID = 1; 29 | public static final int SCHEMA_VERSION = 0; 30 | 31 | private final BidEncoder parentMessage = this; 32 | private MutableDirectBuffer buffer; 33 | protected int offset; 34 | protected int limit; 35 | protected int actingBlockLength; 36 | protected int actingVersion; 37 | 38 | public int sbeBlockLength() 39 | { 40 | return BLOCK_LENGTH; 41 | } 42 | 43 | public int sbeTemplateId() 44 | { 45 | return TEMPLATE_ID; 46 | } 47 | 48 | public int sbeSchemaId() 49 | { 50 | return SCHEMA_ID; 51 | } 52 | 53 | public int sbeSchemaVersion() 54 | { 55 | return SCHEMA_VERSION; 56 | } 57 | 58 | public String sbeSemanticType() 59 | { 60 | return ""; 61 | } 62 | 63 | public int offset() 64 | { 65 | return offset; 66 | } 67 | 68 | public BidEncoder wrap(final MutableDirectBuffer buffer, final int offset) 69 | { 70 | this.buffer = buffer; 71 | this.offset = offset; 72 | limit(offset + BLOCK_LENGTH); 73 | return this; 74 | } 75 | 76 | public int size() 77 | { 78 | return limit - offset; 79 | } 80 | 81 | public int limit() 82 | { 83 | return limit; 84 | } 85 | 86 | public void limit(final int limit) 87 | { 88 | buffer.checkLimit(limit); 89 | this.limit = limit; 90 | } 91 | 92 | public static int auctionIdNullValue() 93 | { 94 | return -2147483648; 95 | } 96 | 97 | public static int auctionIdMinValue() 98 | { 99 | return -2147483647; 100 | } 101 | 102 | public static int auctionIdMaxValue() 103 | { 104 | return 2147483647; 105 | } 106 | public BidEncoder auctionId(final int value) 107 | { 108 | CodecUtil.int32Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 109 | return this; 110 | } 111 | 112 | public static long bidderIdNullValue() 113 | { 114 | return -9223372036854775808L; 115 | } 116 | 117 | public static long bidderIdMinValue() 118 | { 119 | return -9223372036854775807L; 120 | } 121 | 122 | public static long bidderIdMaxValue() 123 | { 124 | return 9223372036854775807L; 125 | } 126 | public BidEncoder bidderId(final long value) 127 | { 128 | CodecUtil.int64Put(buffer, offset + 4, value, java.nio.ByteOrder.LITTLE_ENDIAN); 129 | return this; 130 | } 131 | 132 | public static long valueNullValue() 133 | { 134 | return -9223372036854775808L; 135 | } 136 | 137 | public static long valueMinValue() 138 | { 139 | return -9223372036854775807L; 140 | } 141 | 142 | public static long valueMaxValue() 143 | { 144 | return 9223372036854775807L; 145 | } 146 | public BidEncoder value(final long value) 147 | { 148 | CodecUtil.int64Put(buffer, offset + 12, value, java.nio.ByteOrder.LITTLE_ENDIAN); 149 | return this; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /solutions/advanced-service/src/main/java/amaethon/generated/GroupSizeEncodingDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.DirectBuffer; 23 | 24 | public class GroupSizeEncodingDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public GroupSizeEncodingDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 4; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | 58 | public int blockLength() 59 | { 60 | return CodecUtil.uint16Get(buffer, offset + 0, java.nio.ByteOrder.LITTLE_ENDIAN); 61 | } 62 | 63 | 64 | public static int numInGroupNullValue() 65 | { 66 | return 65535; 67 | } 68 | 69 | public static int numInGroupMinValue() 70 | { 71 | return 0; 72 | } 73 | 74 | public static int numInGroupMaxValue() 75 | { 76 | return 65534; 77 | } 78 | 79 | public int numInGroup() 80 | { 81 | return CodecUtil.uint16Get(buffer, offset + 2, java.nio.ByteOrder.LITTLE_ENDIAN); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /solutions/advanced-service/src/main/java/amaethon/generated/GroupSizeEncodingEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class GroupSizeEncodingEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public GroupSizeEncodingEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 4; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | public GroupSizeEncodingEncoder blockLength(final int value) 58 | { 59 | CodecUtil.uint16Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 60 | return this; 61 | } 62 | 63 | public static int numInGroupNullValue() 64 | { 65 | return 65535; 66 | } 67 | 68 | public static int numInGroupMinValue() 69 | { 70 | return 0; 71 | } 72 | 73 | public static int numInGroupMaxValue() 74 | { 75 | return 65534; 76 | } 77 | public GroupSizeEncodingEncoder numInGroup(final int value) 78 | { 79 | CodecUtil.uint16Put(buffer, offset + 2, value, java.nio.ByteOrder.LITTLE_ENDIAN); 80 | return this; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /solutions/advanced-service/src/main/java/amaethon/generated/MessageHeaderDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.DirectBuffer; 23 | 24 | public class MessageHeaderDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public MessageHeaderDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 8; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | 58 | public int blockLength() 59 | { 60 | return CodecUtil.uint16Get(buffer, offset + 0, java.nio.ByteOrder.LITTLE_ENDIAN); 61 | } 62 | 63 | 64 | public static int templateIdNullValue() 65 | { 66 | return 65535; 67 | } 68 | 69 | public static int templateIdMinValue() 70 | { 71 | return 0; 72 | } 73 | 74 | public static int templateIdMaxValue() 75 | { 76 | return 65534; 77 | } 78 | 79 | public int templateId() 80 | { 81 | return CodecUtil.uint16Get(buffer, offset + 2, java.nio.ByteOrder.LITTLE_ENDIAN); 82 | } 83 | 84 | 85 | public static int schemaIdNullValue() 86 | { 87 | return 65535; 88 | } 89 | 90 | public static int schemaIdMinValue() 91 | { 92 | return 0; 93 | } 94 | 95 | public static int schemaIdMaxValue() 96 | { 97 | return 65534; 98 | } 99 | 100 | public int schemaId() 101 | { 102 | return CodecUtil.uint16Get(buffer, offset + 4, java.nio.ByteOrder.LITTLE_ENDIAN); 103 | } 104 | 105 | 106 | public static int versionNullValue() 107 | { 108 | return 65535; 109 | } 110 | 111 | public static int versionMinValue() 112 | { 113 | return 0; 114 | } 115 | 116 | public static int versionMaxValue() 117 | { 118 | return 65534; 119 | } 120 | 121 | public int version() 122 | { 123 | return CodecUtil.uint16Get(buffer, offset + 6, java.nio.ByteOrder.LITTLE_ENDIAN); 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /solutions/advanced-service/src/main/java/amaethon/generated/MessageHeaderEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class MessageHeaderEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public MessageHeaderEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 8; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | public MessageHeaderEncoder blockLength(final int value) 58 | { 59 | CodecUtil.uint16Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 60 | return this; 61 | } 62 | 63 | public static int templateIdNullValue() 64 | { 65 | return 65535; 66 | } 67 | 68 | public static int templateIdMinValue() 69 | { 70 | return 0; 71 | } 72 | 73 | public static int templateIdMaxValue() 74 | { 75 | return 65534; 76 | } 77 | public MessageHeaderEncoder templateId(final int value) 78 | { 79 | CodecUtil.uint16Put(buffer, offset + 2, value, java.nio.ByteOrder.LITTLE_ENDIAN); 80 | return this; 81 | } 82 | 83 | public static int schemaIdNullValue() 84 | { 85 | return 65535; 86 | } 87 | 88 | public static int schemaIdMinValue() 89 | { 90 | return 0; 91 | } 92 | 93 | public static int schemaIdMaxValue() 94 | { 95 | return 65534; 96 | } 97 | public MessageHeaderEncoder schemaId(final int value) 98 | { 99 | CodecUtil.uint16Put(buffer, offset + 4, value, java.nio.ByteOrder.LITTLE_ENDIAN); 100 | return this; 101 | } 102 | 103 | public static int versionNullValue() 104 | { 105 | return 65535; 106 | } 107 | 108 | public static int versionMinValue() 109 | { 110 | return 0; 111 | } 112 | 113 | public static int versionMaxValue() 114 | { 115 | return 65534; 116 | } 117 | public MessageHeaderEncoder version(final int value) 118 | { 119 | CodecUtil.uint16Put(buffer, offset + 6, value, java.nio.ByteOrder.LITTLE_ENDIAN); 120 | return this; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /solutions/advanced-service/src/main/java/amaethon/generated/MetaAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | public enum MetaAttribute 22 | { 23 | EPOCH, 24 | TIME_UNIT, 25 | SEMANTIC_TYPE 26 | } 27 | -------------------------------------------------------------------------------- /solutions/advanced-service/src/main/java/amaethon/generated/VarDataEncodingDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.DirectBuffer; 23 | 24 | public class VarDataEncodingDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public VarDataEncodingDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return -1; 41 | } 42 | 43 | public static short lengthNullValue() 44 | { 45 | return (short)255; 46 | } 47 | 48 | public static short lengthMinValue() 49 | { 50 | return (short)0; 51 | } 52 | 53 | public static short lengthMaxValue() 54 | { 55 | return (short)254; 56 | } 57 | 58 | public short length() 59 | { 60 | return CodecUtil.uint8Get(buffer, offset + 0); 61 | } 62 | 63 | 64 | public static short varDataNullValue() 65 | { 66 | return (short)255; 67 | } 68 | 69 | public static short varDataMinValue() 70 | { 71 | return (short)0; 72 | } 73 | 74 | public static short varDataMaxValue() 75 | { 76 | return (short)254; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /solutions/advanced-service/src/main/java/amaethon/generated/VarDataEncodingEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class VarDataEncodingEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public VarDataEncodingEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return -1; 41 | } 42 | 43 | public static short lengthNullValue() 44 | { 45 | return (short)255; 46 | } 47 | 48 | public static short lengthMinValue() 49 | { 50 | return (short)0; 51 | } 52 | 53 | public static short lengthMaxValue() 54 | { 55 | return (short)254; 56 | } 57 | public VarDataEncodingEncoder length(final short value) 58 | { 59 | CodecUtil.uint8Put(buffer, offset + 0, value); 60 | return this; 61 | } 62 | 63 | public static short varDataNullValue() 64 | { 65 | return (short)255; 66 | } 67 | 68 | public static short varDataMinValue() 69 | { 70 | return (short)0; 71 | } 72 | 73 | public static short varDataMaxValue() 74 | { 75 | return (short)254; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /solutions/basic-service/src/main/java/amaethon/Auction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import java.util.concurrent.TimeUnit; 21 | 22 | /** 23 | * Encapsulation of an Auction. Instances will be re-used by {@link AuctionHouse}. 24 | */ 25 | public class Auction 26 | { 27 | private static final long LINGER_TIMEOUT_NANOS = TimeUnit.SECONDS.toNanos(10); 28 | 29 | /* 30 | * INACTIVE means Auction not valid 31 | * ACTIVE means Auction is accepting bids 32 | * OVER means Auction is over (Auction will linger for a period of time before being re-used) 33 | */ 34 | enum State 35 | { 36 | INACTIVE, ACTIVE, OVER 37 | } 38 | 39 | private byte[] nameInBytes = new byte[1024]; 40 | private int nameLength; 41 | private long expiration; 42 | private long currentHighBid; 43 | private long currentHighBidder; 44 | private State state; 45 | 46 | public Auction() 47 | { 48 | this.state = State.INACTIVE; 49 | } 50 | 51 | public void reset(final byte[] name, final int nameLength, final long expiration, final long reserveValue) 52 | { 53 | System.arraycopy(name, 0, this.nameInBytes, 0, name.length); 54 | this.nameLength = nameLength; 55 | this.expiration = expiration; 56 | this.currentHighBid = reserveValue; 57 | this.currentHighBidder = Bidder.INVALID_BIDDER; 58 | this.state = State.ACTIVE; 59 | } 60 | 61 | public boolean isInactive() 62 | { 63 | return (State.INACTIVE == state); 64 | } 65 | 66 | public String name() 67 | { 68 | return new String(nameInBytes, 0, nameLength); 69 | } 70 | 71 | public long highBid() 72 | { 73 | return currentHighBid; 74 | } 75 | 76 | public long highBidder() 77 | { 78 | return currentHighBidder; 79 | } 80 | 81 | // return 0 for nothing new or >0 for activity 82 | public int onAdvanceTime(final long now) 83 | { 84 | int result = 0; 85 | 86 | if (State.ACTIVE == state && now > expiration) 87 | { 88 | state = State.OVER; 89 | result = 1; 90 | } 91 | else if (State.OVER == state && now > (expiration + LINGER_TIMEOUT_NANOS)) 92 | { 93 | state = State.INACTIVE; 94 | } 95 | 96 | return result; 97 | } 98 | 99 | // True if high bid. False if not. 100 | public boolean bid(final long bidder, final long value) 101 | { 102 | boolean result = false; 103 | 104 | if (State.ACTIVE == state && value > currentHighBid) 105 | { 106 | currentHighBid = value; 107 | currentHighBidder = bidder; 108 | result = true; 109 | } 110 | 111 | return result; 112 | } 113 | 114 | public void cancel() 115 | { 116 | this.currentHighBidder = Bidder.INVALID_BIDDER; 117 | this.state = State.OVER; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /solutions/basic-service/src/main/java/amaethon/Bidder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import java.util.Arrays; 21 | 22 | /** 23 | * Encapsulation of a bidder 24 | */ 25 | public class Bidder 26 | { 27 | public static final long INVALID_BIDDER = -1; 28 | 29 | private final byte[] name; 30 | private final long id; 31 | private long budget; 32 | 33 | public Bidder(final byte[] name, final long bidderId, final long budget) 34 | { 35 | this.name = Arrays.copyOf(name, name.length); 36 | this.id = bidderId; 37 | this.budget = budget; 38 | } 39 | 40 | public byte[] name() 41 | { 42 | return name; 43 | } 44 | 45 | public long id() 46 | { 47 | return id; 48 | } 49 | 50 | public long budget() 51 | { 52 | return budget; 53 | } 54 | 55 | public void decrementBudget(final long price) 56 | { 57 | budget -= price; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /solutions/basic-service/src/main/java/amaethon/Model.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import java.util.function.Consumer; 21 | 22 | /** 23 | * Interface for an Auction House 24 | */ 25 | public interface Model 26 | { 27 | // add an auction 28 | int add(final byte[] name, final int nameLength, final long expiration, final long reserveValue); 29 | 30 | // cancel an auction 31 | void cancel(final int auctionId); 32 | 33 | // bid on an auction. True if high bid, False if not 34 | boolean bid(final int auctionId, final long bidderId, final long value); 35 | 36 | // iterator over all non-inactive auctions (for activity feed and for advancing time on auctions) 37 | void forEach(final Consumer consumer); 38 | 39 | // done to add a new bidding account to the system 40 | void addBidder(final byte[] name, final long bidderId, final long budget); 41 | } -------------------------------------------------------------------------------- /solutions/basic-service/src/main/java/amaethon/RunExercise.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package amaethon; 19 | 20 | import uk.co.real_logic.aeron.driver.MediaDriver; 21 | 22 | /** 23 | * Runner for the exercise that has a contained Media Driver, AuctionService and AutomatedClient 24 | */ 25 | public class RunExercise 26 | { 27 | public static final String SUBMISSION_CHANNEL = "aeron:udp?remote=localhost:43456"; 28 | public static final int SUBMISSION_STREAM_ID = 1; 29 | 30 | public static void main(final String[] args) throws Exception 31 | { 32 | final MediaDriver.Context ctx = new MediaDriver.Context(); 33 | final MediaDriver mediaDriver = MediaDriver.launch(ctx.dirsDeleteOnStart(true)); 34 | final AuctionService service = new AuctionService(SUBMISSION_CHANNEL, SUBMISSION_STREAM_ID); 35 | final Thread serviceThread = new Thread(service); 36 | final AuctionHouse house = service.house(); 37 | 38 | serviceThread.setName("AuctionService"); 39 | serviceThread.start(); 40 | 41 | try (final AutomatedClient client = new AutomatedClient(SUBMISSION_CHANNEL, SUBMISSION_STREAM_ID)) 42 | { 43 | house.addBidder("tmontgomery".getBytes(), 1, 0); 44 | house.addBidder("mjpt777".getBytes(), 2, 0); 45 | house.addBidder("RichardWarburton".getBytes(), 3, 0); 46 | 47 | client.auction("Star Wars Force Awakens Pre-Pre-Release", 1000000000, "00:00:10"); 48 | client.bid(0, 1, 1000000000 + 1); 49 | client.auction("Issue #1000", 0, "00:00:05"); 50 | client.bid(1, 2, 1); 51 | client.bid(1, 3, 1); 52 | client.bid(1, 1, 2); 53 | 54 | Thread.sleep(11000); 55 | } 56 | 57 | service.shutdown(); 58 | serviceThread.join(); 59 | service.close(); 60 | mediaDriver.close(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /solutions/basic-service/src/main/java/amaethon/generated/BidEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class BidEncoder 25 | { 26 | public static final int BLOCK_LENGTH = 20; 27 | public static final int TEMPLATE_ID = 2; 28 | public static final int SCHEMA_ID = 1; 29 | public static final int SCHEMA_VERSION = 0; 30 | 31 | private final BidEncoder parentMessage = this; 32 | private MutableDirectBuffer buffer; 33 | protected int offset; 34 | protected int limit; 35 | protected int actingBlockLength; 36 | protected int actingVersion; 37 | 38 | public int sbeBlockLength() 39 | { 40 | return BLOCK_LENGTH; 41 | } 42 | 43 | public int sbeTemplateId() 44 | { 45 | return TEMPLATE_ID; 46 | } 47 | 48 | public int sbeSchemaId() 49 | { 50 | return SCHEMA_ID; 51 | } 52 | 53 | public int sbeSchemaVersion() 54 | { 55 | return SCHEMA_VERSION; 56 | } 57 | 58 | public String sbeSemanticType() 59 | { 60 | return ""; 61 | } 62 | 63 | public int offset() 64 | { 65 | return offset; 66 | } 67 | 68 | public BidEncoder wrap(final MutableDirectBuffer buffer, final int offset) 69 | { 70 | this.buffer = buffer; 71 | this.offset = offset; 72 | limit(offset + BLOCK_LENGTH); 73 | return this; 74 | } 75 | 76 | public int size() 77 | { 78 | return limit - offset; 79 | } 80 | 81 | public int limit() 82 | { 83 | return limit; 84 | } 85 | 86 | public void limit(final int limit) 87 | { 88 | buffer.checkLimit(limit); 89 | this.limit = limit; 90 | } 91 | 92 | public static int auctionIdNullValue() 93 | { 94 | return -2147483648; 95 | } 96 | 97 | public static int auctionIdMinValue() 98 | { 99 | return -2147483647; 100 | } 101 | 102 | public static int auctionIdMaxValue() 103 | { 104 | return 2147483647; 105 | } 106 | public BidEncoder auctionId(final int value) 107 | { 108 | CodecUtil.int32Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 109 | return this; 110 | } 111 | 112 | public static long bidderIdNullValue() 113 | { 114 | return -9223372036854775808L; 115 | } 116 | 117 | public static long bidderIdMinValue() 118 | { 119 | return -9223372036854775807L; 120 | } 121 | 122 | public static long bidderIdMaxValue() 123 | { 124 | return 9223372036854775807L; 125 | } 126 | public BidEncoder bidderId(final long value) 127 | { 128 | CodecUtil.int64Put(buffer, offset + 4, value, java.nio.ByteOrder.LITTLE_ENDIAN); 129 | return this; 130 | } 131 | 132 | public static long valueNullValue() 133 | { 134 | return -9223372036854775808L; 135 | } 136 | 137 | public static long valueMinValue() 138 | { 139 | return -9223372036854775807L; 140 | } 141 | 142 | public static long valueMaxValue() 143 | { 144 | return 9223372036854775807L; 145 | } 146 | public BidEncoder value(final long value) 147 | { 148 | CodecUtil.int64Put(buffer, offset + 12, value, java.nio.ByteOrder.LITTLE_ENDIAN); 149 | return this; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /solutions/basic-service/src/main/java/amaethon/generated/MessageHeaderDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.DirectBuffer; 23 | 24 | public class MessageHeaderDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public MessageHeaderDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 8; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | 58 | public int blockLength() 59 | { 60 | return CodecUtil.uint16Get(buffer, offset + 0, java.nio.ByteOrder.LITTLE_ENDIAN); 61 | } 62 | 63 | 64 | public static int templateIdNullValue() 65 | { 66 | return 65535; 67 | } 68 | 69 | public static int templateIdMinValue() 70 | { 71 | return 0; 72 | } 73 | 74 | public static int templateIdMaxValue() 75 | { 76 | return 65534; 77 | } 78 | 79 | public int templateId() 80 | { 81 | return CodecUtil.uint16Get(buffer, offset + 2, java.nio.ByteOrder.LITTLE_ENDIAN); 82 | } 83 | 84 | 85 | public static int schemaIdNullValue() 86 | { 87 | return 65535; 88 | } 89 | 90 | public static int schemaIdMinValue() 91 | { 92 | return 0; 93 | } 94 | 95 | public static int schemaIdMaxValue() 96 | { 97 | return 65534; 98 | } 99 | 100 | public int schemaId() 101 | { 102 | return CodecUtil.uint16Get(buffer, offset + 4, java.nio.ByteOrder.LITTLE_ENDIAN); 103 | } 104 | 105 | 106 | public static int versionNullValue() 107 | { 108 | return 65535; 109 | } 110 | 111 | public static int versionMinValue() 112 | { 113 | return 0; 114 | } 115 | 116 | public static int versionMaxValue() 117 | { 118 | return 65534; 119 | } 120 | 121 | public int version() 122 | { 123 | return CodecUtil.uint16Get(buffer, offset + 6, java.nio.ByteOrder.LITTLE_ENDIAN); 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /solutions/basic-service/src/main/java/amaethon/generated/MessageHeaderEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class MessageHeaderEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public MessageHeaderEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 8; 41 | } 42 | 43 | public static int blockLengthNullValue() 44 | { 45 | return 65535; 46 | } 47 | 48 | public static int blockLengthMinValue() 49 | { 50 | return 0; 51 | } 52 | 53 | public static int blockLengthMaxValue() 54 | { 55 | return 65534; 56 | } 57 | public MessageHeaderEncoder blockLength(final int value) 58 | { 59 | CodecUtil.uint16Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 60 | return this; 61 | } 62 | 63 | public static int templateIdNullValue() 64 | { 65 | return 65535; 66 | } 67 | 68 | public static int templateIdMinValue() 69 | { 70 | return 0; 71 | } 72 | 73 | public static int templateIdMaxValue() 74 | { 75 | return 65534; 76 | } 77 | public MessageHeaderEncoder templateId(final int value) 78 | { 79 | CodecUtil.uint16Put(buffer, offset + 2, value, java.nio.ByteOrder.LITTLE_ENDIAN); 80 | return this; 81 | } 82 | 83 | public static int schemaIdNullValue() 84 | { 85 | return 65535; 86 | } 87 | 88 | public static int schemaIdMinValue() 89 | { 90 | return 0; 91 | } 92 | 93 | public static int schemaIdMaxValue() 94 | { 95 | return 65534; 96 | } 97 | public MessageHeaderEncoder schemaId(final int value) 98 | { 99 | CodecUtil.uint16Put(buffer, offset + 4, value, java.nio.ByteOrder.LITTLE_ENDIAN); 100 | return this; 101 | } 102 | 103 | public static int versionNullValue() 104 | { 105 | return 65535; 106 | } 107 | 108 | public static int versionMinValue() 109 | { 110 | return 0; 111 | } 112 | 113 | public static int versionMaxValue() 114 | { 115 | return 65534; 116 | } 117 | public MessageHeaderEncoder version(final int value) 118 | { 119 | CodecUtil.uint16Put(buffer, offset + 6, value, java.nio.ByteOrder.LITTLE_ENDIAN); 120 | return this; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /solutions/basic-service/src/main/java/amaethon/generated/MetaAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | public enum MetaAttribute 22 | { 23 | EPOCH, 24 | TIME_UNIT, 25 | SEMANTIC_TYPE 26 | } 27 | -------------------------------------------------------------------------------- /solutions/basic-service/src/main/java/amaethon/generated/PriceDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.DirectBuffer; 23 | 24 | public class PriceDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public PriceDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 9; 41 | } 42 | 43 | public static long mantissaNullValue() 44 | { 45 | return -9223372036854775808L; 46 | } 47 | 48 | public static long mantissaMinValue() 49 | { 50 | return -9223372036854775807L; 51 | } 52 | 53 | public static long mantissaMaxValue() 54 | { 55 | return 9223372036854775807L; 56 | } 57 | 58 | public long mantissa() 59 | { 60 | return CodecUtil.int64Get(buffer, offset + 0, java.nio.ByteOrder.LITTLE_ENDIAN); 61 | } 62 | 63 | 64 | public static byte exponentNullValue() 65 | { 66 | return (byte)-128; 67 | } 68 | 69 | public static byte exponentMinValue() 70 | { 71 | return (byte)-127; 72 | } 73 | 74 | public static byte exponentMaxValue() 75 | { 76 | return (byte)127; 77 | } 78 | 79 | public byte exponent() 80 | { 81 | return CodecUtil.int8Get(buffer, offset + 8); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /solutions/basic-service/src/main/java/amaethon/generated/PriceEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class PriceEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public PriceEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return 9; 41 | } 42 | 43 | public static long mantissaNullValue() 44 | { 45 | return -9223372036854775808L; 46 | } 47 | 48 | public static long mantissaMinValue() 49 | { 50 | return -9223372036854775807L; 51 | } 52 | 53 | public static long mantissaMaxValue() 54 | { 55 | return 9223372036854775807L; 56 | } 57 | public PriceEncoder mantissa(final long value) 58 | { 59 | CodecUtil.int64Put(buffer, offset + 0, value, java.nio.ByteOrder.LITTLE_ENDIAN); 60 | return this; 61 | } 62 | 63 | public static byte exponentNullValue() 64 | { 65 | return (byte)-128; 66 | } 67 | 68 | public static byte exponentMinValue() 69 | { 70 | return (byte)-127; 71 | } 72 | 73 | public static byte exponentMaxValue() 74 | { 75 | return (byte)127; 76 | } 77 | public PriceEncoder exponent(final byte value) 78 | { 79 | CodecUtil.int8Put(buffer, offset + 8, value); 80 | return this; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /solutions/basic-service/src/main/java/amaethon/generated/VarDataEncodingDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.DirectBuffer; 23 | 24 | public class VarDataEncodingDecoder 25 | { 26 | private DirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public VarDataEncodingDecoder wrap(final DirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return -1; 41 | } 42 | 43 | public static short lengthNullValue() 44 | { 45 | return (short)255; 46 | } 47 | 48 | public static short lengthMinValue() 49 | { 50 | return (short)0; 51 | } 52 | 53 | public static short lengthMaxValue() 54 | { 55 | return (short)254; 56 | } 57 | 58 | public short length() 59 | { 60 | return CodecUtil.uint8Get(buffer, offset + 0); 61 | } 62 | 63 | 64 | public static short varDataNullValue() 65 | { 66 | return (short)255; 67 | } 68 | 69 | public static short varDataMinValue() 70 | { 71 | return (short)0; 72 | } 73 | 74 | public static short varDataMaxValue() 75 | { 76 | return (short)254; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /solutions/basic-service/src/main/java/amaethon/generated/VarDataEncodingEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Real Logic Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | /* Generated SBE (Simple Binary Encoding) message codec */ 19 | package amaethon.generated; 20 | 21 | import uk.co.real_logic.sbe.codec.java.*; 22 | import uk.co.real_logic.agrona.MutableDirectBuffer; 23 | 24 | public class VarDataEncodingEncoder 25 | { 26 | private MutableDirectBuffer buffer; 27 | private int offset; 28 | private int actingVersion; 29 | 30 | public VarDataEncodingEncoder wrap(final MutableDirectBuffer buffer, final int offset, final int actingVersion) 31 | { 32 | this.buffer = buffer; 33 | this.offset = offset; 34 | this.actingVersion = actingVersion; 35 | return this; 36 | } 37 | 38 | public int size() 39 | { 40 | return -1; 41 | } 42 | 43 | public static short lengthNullValue() 44 | { 45 | return (short)255; 46 | } 47 | 48 | public static short lengthMinValue() 49 | { 50 | return (short)0; 51 | } 52 | 53 | public static short lengthMaxValue() 54 | { 55 | return (short)254; 56 | } 57 | public VarDataEncodingEncoder length(final short value) 58 | { 59 | CodecUtil.uint8Put(buffer, offset + 0, value); 60 | return this; 61 | } 62 | 63 | public static short varDataNullValue() 64 | { 65 | return (short)255; 66 | } 67 | 68 | public static short varDataMinValue() 69 | { 70 | return (short)0; 71 | } 72 | 73 | public static short varDataMaxValue() 74 | { 75 | return (short)254; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /solutions/basic-service/src/main/resources/Amaethon-schema.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | --------------------------------------------------------------------------------