index
int64
repo_id
string
file_path
string
content
string
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/ComparisonOperatorParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.util.Builder; final class ComparisonOperatorParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final Builder<I, V> builder; final Parser<V> lhsParser; final String operator; final Parser<V> rhsParser; final int step; ComparisonOperatorParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> lhsParser, String operator, Parser<V> rhsParser, int step) { this.recon = recon; this.builder = builder; this.lhsParser = lhsParser; this.operator = operator; this.rhsParser = rhsParser; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.builder, this.lhsParser, this.operator, this.rhsParser, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> lhsParser, String operator, Parser<V> rhsParser, int step) { int c = 0; if (step == 1) { if (lhsParser == null) { lhsParser = recon.parseAttrExpression(input, builder); } while (lhsParser.isCont() && !input.isEmpty()) { lhsParser = lhsParser.feed(input); } if (lhsParser.isDone()) { step = 2; } else if (lhsParser.isError()) { return lhsParser.asError(); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Recon.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == '!') { input = input.step(); step = 3; } else if (c == '<') { input = input.step(); step = 4; } else if (c == '>') { input = input.step(); step = 5; } else if (c == '=') { input = input.step(); step = 6; } else { return lhsParser; } } else if (input.isDone()) { return lhsParser; } } if (step == 3) { if (input.isCont()) { c = input.head(); if (c == '=') { input = input.step(); operator = "!="; step = 7; } else { operator = "!"; step = 7; } } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 4) { if (input.isCont()) { c = input.head(); if (c == '=') { input = input.step(); operator = "<="; step = 7; } else { operator = "<"; step = 7; } } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 5) { if (input.isCont()) { c = input.head(); if (c == '=') { input = input.step(); operator = ">="; step = 7; } else { operator = ">"; step = 7; } } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 6) { if (input.isCont()) { c = input.head(); if (c == '=') { input = input.step(); operator = "=="; step = 7; } else if (c == '>') { return lhsParser; } else { operator = "="; step = 7; } } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 7) { if (rhsParser == null) { rhsParser = recon.parseAttrExpression(input, builder); } while (rhsParser.isCont() && !input.isEmpty()) { rhsParser = rhsParser.feed(input); } if (rhsParser.isDone()) { final V lhs = lhsParser.bind(); final V rhs = rhsParser.bind(); if ("<".equals(operator)) { return done(recon.lt(lhs, rhs)); } else if ("<=".equals(operator)) { return done(recon.le(lhs, rhs)); } else if ("==".equals(operator)) { return done(recon.eq(lhs, rhs)); } else if ("!=".equals(operator)) { return done(recon.ne(lhs, rhs)); } else if (">=".equals(operator)) { return done(recon.ge(lhs, rhs)); } else if (">".equals(operator)) { return done(recon.gt(lhs, rhs)); } else { return error(Diagnostic.message(operator, input)); } } else if (rhsParser.isError()) { return rhsParser.asError(); } } if (input.isError()) { return error(input.trap()); } return new ComparisonOperatorParser<I, V>(recon, builder, lhsParser, operator, rhsParser, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) { return parse(input, recon, builder, null, null, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/ConditionalOperatorParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.util.Builder; final class ConditionalOperatorParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final Builder<I, V> builder; final Parser<V> ifParser; final Parser<V> thenParser; final Parser<V> elseParser; final int step; ConditionalOperatorParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> ifParser, Parser<V> thenParser, Parser<V> elseParser, int step) { this.recon = recon; this.builder = builder; this.ifParser = ifParser; this.thenParser = thenParser; this.elseParser = elseParser; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.builder, this.ifParser, this.thenParser, this.elseParser, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> ifParser, Parser<V> thenParser, Parser<V> elseParser, int step) { int c = 0; if (step == 1) { if (ifParser == null) { ifParser = recon.parseOrOperator(input, builder); } while (ifParser.isCont() && !input.isEmpty()) { ifParser = ifParser.feed(input); } if (ifParser.isDone()) { step = 2; } else if (ifParser.isError()) { return ifParser.asError(); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Recon.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == '?') { input = input.step(); step = 3; } else { return ifParser; } } else if (input.isDone()) { return ifParser; } } if (step == 3) { if (thenParser == null) { thenParser = recon.parseConditionalOperator(input, builder); } while (thenParser.isCont() && !input.isEmpty()) { thenParser = thenParser.feed(input); } if (thenParser.isDone()) { step = 4; } else if (thenParser.isError()) { return thenParser.asError(); } } if (step == 4) { while (input.isCont()) { c = input.head(); if (Recon.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == ':') { input = input.step(); step = 5; } else { return error(Diagnostic.expected(':', input)); } } else if (input.isDone()) { return error(Diagnostic.expected(':', input)); } } if (step == 5) { if (elseParser == null) { elseParser = recon.parseConditionalOperator(input, builder); } while (elseParser.isCont() && !input.isEmpty()) { elseParser = elseParser.feed(input); } if (elseParser.isDone()) { final V ifTerm = ifParser.bind(); final V thenTerm = thenParser.bind(); final V elseTerm = elseParser.bind(); return done(recon.conditional(ifTerm, thenTerm, elseTerm)); } else if (elseParser.isError()) { return elseParser.asError(); } } if (input.isError()) { return error(input.trap()); } return new ConditionalOperatorParser<I, V>(recon, builder, ifParser, thenParser, elseParser, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) { return parse(input, recon, builder, null, null, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/ConditionalOperatorWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class ConditionalOperatorWriter<I, V> extends Writer<Object, Object> { final ReconWriter<I, V> recon; final I ifTerm; final I thenTerm; final I elseTerm; final int precedence; final Writer<?, ?> part; final int step; ConditionalOperatorWriter(ReconWriter<I, V> recon, I ifTerm, I thenTerm, I elseTerm, int precedence, Writer<?, ?> part, int step) { this.recon = recon; this.ifTerm = ifTerm; this.thenTerm = thenTerm; this.elseTerm = elseTerm; this.precedence = precedence; this.part = part; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.recon, this.ifTerm, this.thenTerm, this.elseTerm, this.precedence, this.part, this.step); } static <I, V> int sizeOf(ReconWriter<I, V> recon, I ifTerm, I thenTerm, I elseTerm, int precedence) { int size = 0; if (recon.precedence(ifTerm) > 0 && recon.precedence(ifTerm) <= precedence) { size += 1; // '(' size += recon.sizeOfItem(ifTerm); size += 1; // ')' } else { size += recon.sizeOfItem(ifTerm); } size += 3; // " ? " size += recon.sizeOfItem(thenTerm); size += 3; // " : " size += recon.sizeOfItem(elseTerm); return size; } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, I ifTerm, I thenTerm, I elseTerm, int precedence, Writer<?, ?> part, int step) { if (step == 1) { if (recon.precedence(ifTerm) > 0 && recon.precedence(ifTerm) <= precedence) { if (output.isCont()) { output = output.write('('); step = 2; } } else { step = 2; } } if (step == 2) { if (part == null) { part = recon.writeItem(ifTerm, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 3; } else if (part.isError()) { return part.asError(); } } if (step == 3) { if (recon.precedence(ifTerm) > 0 && recon.precedence(ifTerm) <= precedence) { if (output.isCont()) { output = output.write(')'); step = 4; } } else { step = 4; } } if (step == 4 && output.isCont()) { output = output.write(' '); step = 5; } if (step == 5 && output.isCont()) { output = output.write('?'); step = 6; } if (step == 6 && output.isCont()) { output = output.write(' '); step = 7; } if (step == 7) { if (part == null) { part = recon.writeItem(thenTerm, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 8; } else if (part.isError()) { return part.asError(); } } if (step == 8 && output.isCont()) { output = output.write(' '); step = 9; } if (step == 9 && output.isCont()) { output = output.write(':'); step = 10; } if (step == 10 && output.isCont()) { output = output.write(' '); step = 11; } if (step == 11) { if (part == null) { part = recon.writeItem(elseTerm, output); } else { part = part.pull(output); } if (part.isDone()) { return done(); } else if (part.isError()) { return part.asError(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new ConditionalOperatorWriter<I, V>(recon, ifTerm, thenTerm, elseTerm, precedence, part, step); } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, I ifTerm, I thenTerm, I elseTerm, int precedence) { return write(output, recon, ifTerm, thenTerm, elseTerm, precedence, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/DataParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Base64; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; final class DataParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final Parser<V> base64Parser; final int step; DataParser(ReconParser<I, V> recon, Parser<V> base64Parser, int step) { this.recon = recon; this.base64Parser = base64Parser; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.base64Parser, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Parser<V> base64Parser, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (c == '%') { input = input.step(); step = 2; } else { return error(Diagnostic.expected('%', input)); } } else if (input.isDone()) { return error(Diagnostic.expected('%', input)); } } if (step == 2) { if (base64Parser == null) { base64Parser = Base64.standard().parse(input, recon.dataOutput()); } while (base64Parser.isCont() && !input.isEmpty()) { base64Parser = base64Parser.feed(input); } if (base64Parser.isDone()) { return base64Parser; } else if (base64Parser.isError()) { return base64Parser; } } if (input.isError()) { return error(input.trap()); } return new DataParser<I, V>(recon, base64Parser, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon) { return parse(input, recon, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/DataWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import java.nio.ByteBuffer; import swim.codec.Base64; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class DataWriter extends Writer<Object, Object> { final ByteBuffer buffer; final Writer<?, ?> part; final int step; DataWriter(ByteBuffer buffer, Writer<?, ?> part, int step) { this.buffer = buffer; this.part = part; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.buffer, this.part, this.step); } static int sizeOf(int length) { return 1 + (((length * 4 / 3) + 3) & ~3); } static Writer<Object, Object> write(Output<?> output, ByteBuffer buffer, Writer<?, ?> part, int step) { if (step == 1 && output.isCont()) { output = output.write('%'); step = 2; } if (step == 2) { if (part == null) { part = Base64.standard().writeByteBuffer(buffer, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; return done(); } else if (part.isError()) { return part.asError(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new DataWriter(buffer, part, step); } static Writer<Object, Object> write(Output<?> output, ByteBuffer buffer) { return write(output, buffer, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/DescendantsSelectorWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class DescendantsSelectorWriter<I, V> extends Writer<Object, Object> { final ReconWriter<I, V> recon; final V then; final int step; DescendantsSelectorWriter(ReconWriter<I, V> recon, V then, int step) { this.recon = recon; this.then = then; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.recon, this.then, this.step); } static <I, V> int sizeOf(ReconWriter<I, V> recon, V then) { int size = 3; // ('$' | '.') '*' '*' size += recon.sizeOfThen(then); return size; } @SuppressWarnings("unchecked") static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V then, int step) { if (step == 1 && output.isCont()) { output = output.write('$'); step = 3; } else if (step == 2 && output.isCont()) { output = output.write('.'); step = 3; } if (step == 3 && output.isCont()) { output = output.write('*'); step = 4; } if (step == 4 && output.isCont()) { output = output.write('*'); return (Writer<Object, Object>) recon.writeThen(then, output); } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new DescendantsSelectorWriter<I, V>(recon, then, step); } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V then) { return write(output, recon, then, 1); } static <I, V> Writer<Object, Object> writeThen(Output<?> output, ReconWriter<I, V> recon, V then) { return write(output, recon, then, 2); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/FilterSelectorWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class FilterSelectorWriter<I, V> extends Writer<Object, Object> { final ReconWriter<I, V> recon; final V predicate; final V then; final Writer<?, ?> part; final int step; FilterSelectorWriter(ReconWriter<I, V> recon, V predicate, V then, Writer<?, ?> part, int step) { this.recon = recon; this.predicate = predicate; this.then = then; this.part = part; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.recon, this.predicate, this.then, this.part, this.step); } static <I, V> int sizeOf(ReconWriter<I, V> recon, V predicate, V then) { int size = 2; // '$' '[' size += recon.sizeOfValue(predicate); size += 1; // ']' size += recon.sizeOfThen(then); return size; } static <I, V> int sizeOfThen(ReconWriter<I, V> recon, V predicate, V then) { int size = 1; // '[' size += recon.sizeOfValue(predicate); size += 1; // ']' size += recon.sizeOfThen(then); return size; } @SuppressWarnings("unchecked") static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V predicate, V then, Writer<?, ?> part, int step) { if (step == 1 && output.isCont()) { output = output.write('$'); step = 2; } if (step == 2 && output.isCont()) { output = output.write('['); step = 3; } if (step == 3) { if (part == null) { part = recon.writeValue(predicate, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 4; } else if (part.isError()) { return part.asError(); } } if (step == 4 && output.isCont()) { output = output.write(']'); return (Writer<Object, Object>) recon.writeThen(then, output); } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new FilterSelectorWriter<I, V>(recon, predicate, then, part, step); } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V predicate, V then) { return write(output, recon, predicate, then, null, 1); } static <I, V> Writer<Object, Object> writeThen(Output<?> output, ReconWriter<I, V> recon, V predicate, V then) { return write(output, recon, predicate, then, null, 2); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/GetAttrSelectorWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class GetAttrSelectorWriter<I, V> extends Writer<Object, Object> { final ReconWriter<I, V> recon; final V key; final V then; final Writer<?, ?> part; final int step; GetAttrSelectorWriter(ReconWriter<I, V> recon, V key, V then, Writer<?, ?> part, int step) { this.recon = recon; this.key = key; this.then = then; this.part = part; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.recon, this.key, this.then, this.part, this.step); } static <I, V> int sizeOf(ReconWriter<I, V> recon, V key, V then) { int size = 2; // ('$' | '.') '@' size += recon.sizeOfValue(key); size += recon.sizeOfThen(then); return size; } @SuppressWarnings("unchecked") static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V key, V then, Writer<?, ?> part, int step) { if (step == 1 && output.isCont()) { output = output.write('$'); step = 3; } else if (step == 2 && output.isCont()) { output = output.write('.'); step = 3; } if (step == 3 && output.isCont()) { output = output.write('@'); step = 4; } if (step == 4) { if (part == null) { part = recon.writeValue(key, output); } else { part = part.pull(output); } if (part.isDone()) { return (Writer<Object, Object>) recon.writeThen(then, output); } else if (part.isError()) { return part.asError(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new GetAttrSelectorWriter<I, V>(recon, key, then, part, step); } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V key, V then) { return write(output, recon, key, then, null, 1); } static <I, V> Writer<Object, Object> writeThen(Output<?> output, ReconWriter<I, V> recon, V key, V then) { return write(output, recon, key, then, null, 2); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/GetItemSelectorWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class GetItemSelectorWriter<I, V> extends Writer<Object, Object> { final ReconWriter<I, V> recon; final V index; final V then; final Writer<?, ?> part; final int step; GetItemSelectorWriter(ReconWriter<I, V> recon, V index, V then, Writer<?, ?> part, int step) { this.recon = recon; this.index = index; this.then = then; this.part = part; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.recon, this.index, this.then, this.part, this.step); } static <I, V> int sizeOf(ReconWriter<I, V> recon, V index, V then) { int size = 2; // "$#" size += recon.sizeOfValue(index); size += recon.sizeOfThen(then); return size; } static <I, V> int sizeOfThen(ReconWriter<I, V> recon, V index, V then) { int size = 1; // '#' size += recon.sizeOfValue(index); size += recon.sizeOfThen(then); return size; } @SuppressWarnings("unchecked") static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V index, V then, Writer<?, ?> part, int step) { if (step == 1 && output.isCont()) { output = output.write('$'); step = 2; } if (step == 2 && output.isCont()) { output = output.write('#'); step = 3; } if (step == 3) { if (part == null) { part = recon.writeValue(index, output); } else { part = part.pull(output); } if (part.isDone()) { return (Writer<Object, Object>) recon.writeThen(then, output); } else if (part.isError()) { return part.asError(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new GetItemSelectorWriter<I, V>(recon, index, then, part, step); } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V index, V then) { return write(output, recon, index, then, null, 1); } static <I, V> Writer<Object, Object> writeThen(Output<?> output, ReconWriter<I, V> recon, V index, V then) { return write(output, recon, index, then, null, 2); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/GetSelectorWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class GetSelectorWriter<I, V> extends Writer<Object, Object> { final ReconWriter<I, V> recon; final V key; final V then; final Writer<?, ?> part; final int step; GetSelectorWriter(ReconWriter<I, V> recon, V key, V then, Writer<?, ?> part, int step) { this.recon = recon; this.key = key; this.then = then; this.part = part; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.recon, this.key, this.then, this.part, this.step); } static <I, V> int sizeOf(ReconWriter<I, V> recon, V key, V then) { int size = 1; // '$' | '.' if (recon.isRecord(recon.item(key))) { size += 1; // '{' size += recon.sizeOfBlockValue(key); size += 1; // '}' } else { size += recon.sizeOfValue(key); } size += recon.sizeOfThen(then); return size; } @SuppressWarnings("unchecked") static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V key, V then, Writer<?, ?> part, int step) { if (step == 1 && output.isCont()) { output = output.write('$'); step = 3; } else if (step == 2 && output.isCont()) { output = output.write('.'); step = 3; } if (step == 3) { if (recon.isRecord(recon.item(key))) { if (output.isCont()) { output = output.write('{'); step = 4; } } else { step = 4; } } if (step == 4) { if (part == null) { if (recon.isRecord(recon.item(key))) { part = recon.writeBlockValue(key, output); } else { part = recon.writeValue(key, output); } } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 5; } else if (part.isError()) { return part.asError(); } } if (step == 5) { if (recon.isRecord(recon.item(key))) { if (output.isCont()) { output = output.write('}'); step = 6; } } else { step = 6; } } if (step == 6) { return (Writer<Object, Object>) recon.writeThen(then, output); } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new GetSelectorWriter<I, V>(recon, key, then, part, step); } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V key, V then) { return write(output, recon, key, then, null, 1); } static <I, V> Writer<Object, Object> writeThen(Output<?> output, ReconWriter<I, V> recon, V key, V then) { return write(output, recon, key, then, null, 2); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/IdentParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; final class IdentParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final Output<V> output; final int step; IdentParser(ReconParser<I, V> recon, Output<V> output, int step) { this.recon = recon; this.output = output; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.output, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Output<V> output, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (Recon.isIdentStartChar(c)) { input = input.step(); if (output == null) { output = recon.textOutput(); } output = output.write(c); step = 2; } else { return error(Diagnostic.expected("identifier", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("identifier", input)); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Recon.isIdentChar(c)) { input = input.step(); output = output.write(c); } else { break; } } if (!input.isEmpty()) { return done(recon.ident(output.bind())); } } if (input.isError()) { return error(input.trap()); } return new IdentParser<I, V>(recon, output, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Output<V> output) { return parse(input, recon, output, 1); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon) { return parse(input, recon, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/IdentWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Output; import swim.codec.Utf8; import swim.codec.Writer; import swim.codec.WriterException; final class IdentWriter extends Writer<Object, Object> { final String ident; final int index; IdentWriter(String ident, int index) { this.ident = ident; this.index = index; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.ident, this.index); } static int sizeOf(String ident) { return Utf8.sizeOf(ident); } static Writer<Object, Object> write(Output<?> output, String ident, int index) { int c; final int length = ident.length(); if (length == 0) { return error(new WriterException("empty identifier")); } if (index == 0 && output.isCont()) { c = ident.codePointAt(0); if (Recon.isIdentStartChar(c)) { output = output.write(c); index = ident.offsetByCodePoints(0, 1); } } while (index < length && output.isCont()) { c = ident.codePointAt(index); if (Recon.isIdentChar(c)) { output = output.write(c); index = ident.offsetByCodePoints(index, 1); } else { return error(new WriterException("invalid identifier")); } } if (index >= length) { return done(); } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new IdentWriter(ident, index); } static Writer<Object, Object> write(Output<?> output, String ident) { return write(output, ident, 0); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/InfixOperatorWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Output; import swim.codec.Unicode; import swim.codec.Utf8; import swim.codec.Writer; import swim.codec.WriterException; final class InfixOperatorWriter<I, V> extends Writer<Object, Object> { final ReconWriter<I, V> recon; final I lhs; final String operator; final I rhs; final int precedence; final Writer<?, ?> part; final int step; InfixOperatorWriter(ReconWriter<I, V> recon, I lhs, String operator, I rhs, int precedence, Writer<?, ?> part, int step) { this.recon = recon; this.lhs = lhs; this.operator = operator; this.rhs = rhs; this.precedence = precedence; this.part = part; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.recon, this.lhs, this.operator, this.rhs, this.precedence, this.part, this.step); } static <I, V> int sizeOf(ReconWriter<I, V> recon, I lhs, String operator, I rhs, int precedence) { int size = 0; if (recon.precedence(lhs) < precedence) { size += 1; // '(' size += recon.sizeOfItem(lhs); size += 1; // ')' } else { size += recon.sizeOfItem(lhs); } size += 1; // ' ' size += Utf8.sizeOf(operator); size += 1; // ' ' if (recon.precedence(rhs) < precedence) { size += 1; // '(' size += recon.sizeOfItem(rhs); size += 1; // ')' } else { size += recon.sizeOfItem(rhs); } return size; } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, I lhs, String operator, I rhs, int precedence, Writer<?, ?> part, int step) { if (step == 1) { if (recon.precedence(lhs) < precedence) { if (output.isCont()) { output = output.write('('); step = 2; } } else { step = 2; } } if (step == 2) { if (part == null) { part = recon.writeItem(lhs, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 3; } else if (part.isError()) { return part.asError(); } } if (step == 3) { if (recon.precedence(lhs) < precedence) { if (output.isCont()) { output = output.write(')'); step = 4; } } else { step = 4; } } if (step == 4 && output.isCont()) { output = output.write(' '); step = 5; } if (step == 5) { if (part == null) { part = Unicode.writeString(operator, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 6; } else if (part.isError()) { return part.asError(); } } if (step == 6 && output.isCont()) { output = output.write(' '); step = 7; } if (step == 7) { if (recon.precedence(rhs) < precedence) { if (output.isCont()) { output = output.write('('); step = 8; } } else { step = 8; } } if (step == 8) { if (part == null) { part = recon.writeItem(rhs, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 9; } else if (part.isError()) { return part.asError(); } } if (step == 9) { if (recon.precedence(rhs) < precedence) { if (output.isCont()) { output = output.write(')'); return done(); } } else { return done(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new InfixOperatorWriter<I, V>(recon, lhs, operator, rhs, precedence, part, step); } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, I lhs, String operator, I rhs, int precedence) { return write(output, recon, lhs, operator, rhs, precedence, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/InlineItemParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Input; import swim.codec.Parser; import swim.util.Builder; final class InlineItemParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final Builder<I, V> builder; final Parser<I> fieldParser; final Parser<V> valueParser; final int step; InlineItemParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<I> fieldParser, Parser<V> valueParser, int step) { this.recon = recon; this.builder = builder; this.fieldParser = fieldParser; this.valueParser = valueParser; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.builder, this.fieldParser, this.valueParser, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder, Parser<I> fieldParser, Parser<V> valueParser, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (c == '@') { fieldParser = recon.parseAttr(input); step = 2; } else if (c == '{') { if (builder != null) { valueParser = recon.parseRecord(input, builder); step = 5; } else { valueParser = recon.parseRecord(input); step = 4; } } else if (c == '[') { if (builder != null) { valueParser = recon.parseMarkup(input, builder); step = 5; } else { valueParser = recon.parseMarkup(input); step = 4; } } else if (builder == null) { return done(recon.extant()); } else { return done(builder.bind()); } } else if (input.isDone()) { if (builder == null) { return done(recon.extant()); } else { return done(builder.bind()); } } } if (step == 2) { while (fieldParser.isCont() && !input.isEmpty()) { fieldParser = fieldParser.feed(input); } if (fieldParser.isDone()) { if (builder == null) { builder = recon.valueBuilder(); } builder.add(fieldParser.bind()); fieldParser = null; step = 3; } else if (fieldParser.isError()) { return fieldParser.asError(); } } if (step == 3) { if (input.isCont()) { c = input.head(); if (c == '{') { valueParser = recon.parseRecord(input, builder); step = 5; } else if (c == '[') { valueParser = recon.parseMarkup(input, builder); step = 5; } else { return done(builder.bind()); } } else if (input.isDone()) { return done(builder.bind()); } } if (step == 4) { while (valueParser.isCont() && !input.isEmpty()) { valueParser = valueParser.feed(input); } if (valueParser.isDone()) { if (builder == null) { builder = recon.valueBuilder(); } builder.add(recon.item(valueParser.bind())); return done(builder.bind()); } else if (valueParser.isError()) { return valueParser; } } if (step == 5) { while (valueParser.isCont() && !input.isEmpty()) { valueParser = valueParser.feed(input); } if (valueParser.isDone()) { return done(builder.bind()); } else if (valueParser.isError()) { return valueParser; } } if (input.isError()) { return error(input.trap()); } return new InlineItemParser<I, V>(recon, builder, fieldParser, valueParser, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon) { return parse(input, recon, null, null, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/InvokeOperatorParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.util.Builder; final class InvokeOperatorParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final Builder<I, V> builder; final Parser<V> exprParser; final Parser<V> argsParser; final int step; InvokeOperatorParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> exprParser, Parser<V> argsParser, int step) { this.recon = recon; this.builder = builder; this.exprParser = exprParser; this.argsParser = argsParser; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.builder, this.exprParser, this.argsParser, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> exprParser, Parser<V> argsParser, int step) { int c = 0; if (step == 1) { if (exprParser == null) { exprParser = recon.parsePrimary(input, builder); } while (exprParser.isCont() && !input.isEmpty()) { exprParser = exprParser.feed(input); } if (exprParser.isDone()) { step = 2; } else if (exprParser.isError()) { return exprParser.asError(); } } do { if (step == 2) { while (input.isCont()) { c = input.head(); if (Recon.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == '(') { input = input.step(); step = 3; } else { return exprParser; } } else if (input.isDone()) { return exprParser; } } if (step == 3) { while (input.isCont()) { c = input.head(); if (Recon.isWhitespace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == ')') { input = input.step(); final V expr = exprParser.bind(); exprParser = done(recon.invoke(expr, recon.extant())); step = 2; continue; } else { step = 4; } } else if (input.isDone()) { return error(Diagnostic.expected(')', input)); } } if (step == 4) { if (argsParser == null) { argsParser = recon.parseBlock(input); } while (argsParser.isCont() && !input.isEmpty()) { argsParser = argsParser.feed(input); } if (argsParser.isDone()) { step = 5; } else if (argsParser.isError()) { return argsParser.asError(); } } if (step == 5) { while (input.isCont()) { c = input.head(); if (Recon.isWhitespace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == ')') { input = input.step(); final V expr = exprParser.bind(); final V args = argsParser.bind(); exprParser = done(recon.invoke(expr, args)); argsParser = null; step = 2; continue; } else { return error(Diagnostic.expected(')', input)); } } else if (input.isDone()) { return error(Diagnostic.expected(')', input)); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new InvokeOperatorParser<I, V>(recon, builder, exprParser, argsParser, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) { return parse(input, recon, builder, null, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/InvokeOperatorWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class InvokeOperatorWriter<I, V> extends Writer<Object, Object> { final ReconWriter<I, V> recon; final V func; final V args; final Writer<?, ?> part; final int step; InvokeOperatorWriter(ReconWriter<I, V> recon, V func, V args, Writer<?, ?> part, int step) { this.recon = recon; this.func = func; this.args = args; this.part = part; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.recon, this.func, this.args, this.part, this.step); } static <I, V> int sizeOf(ReconWriter<I, V> recon, V func, V args) { int size = 0; size += recon.sizeOfValue(func); size += 1; // '(' size += recon.sizeOfBlockValue(args); size += 1; // ')' return size; } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V func, V args, Writer<?, ?> part, int step) { if (step == 1) { if (part == null) { part = recon.writeValue(func, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 2; } else if (part.isError()) { return part.asError(); } } if (step == 2 && output.isCont()) { output = output.write('('); step = 3; } if (step == 3) { if (part == null) { part = recon.writeBlockValue(args, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 4; } else if (part.isError()) { return part.asError(); } } if (step == 4 && output.isCont()) { output = output.write(')'); return done(); } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new InvokeOperatorWriter<I, V>(recon, func, args, part, step); } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V func, V args) { return write(output, recon, func, args, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/KeysSelectorWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class KeysSelectorWriter<I, V> extends Writer<Object, Object> { final ReconWriter<I, V> recon; final V then; final int step; KeysSelectorWriter(ReconWriter<I, V> recon, V then, int step) { this.recon = recon; this.then = then; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.recon, this.then, this.step); } static <I, V> int sizeOf(ReconWriter<I, V> recon, V then) { int size = 3; // ('$' | '.') '*' ':' size += recon.sizeOfThen(then); return size; } @SuppressWarnings("unchecked") static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V then, int step) { if (step == 1 && output.isCont()) { output = output.write('$'); step = 3; } else if (step == 2 && output.isCont()) { output = output.write('.'); step = 3; } if (step == 3 && output.isCont()) { output = output.write('*'); step = 4; } if (step == 4 && output.isCont()) { output = output.write(':'); return (Writer<Object, Object>) recon.writeThen(then, output); } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new KeysSelectorWriter<I, V>(recon, then, step); } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V then) { return write(output, recon, then, 1); } static <I, V> Writer<Object, Object> writeThen(Output<?> output, ReconWriter<I, V> recon, V then) { return write(output, recon, then, 2); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/LambdaFuncParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Input; import swim.codec.Parser; import swim.util.Builder; final class LambdaFuncParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final Builder<I, V> builder; final Parser<V> bindingsParser; final Parser<V> templateParser; final int step; LambdaFuncParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> bindingsParser, Parser<V> templateParser, int step) { this.recon = recon; this.builder = builder; this.bindingsParser = bindingsParser; this.templateParser = templateParser; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.builder, this.bindingsParser, this.templateParser, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> bindingsParser, Parser<V> templateParser, int step) { int c = 0; if (step == 1) { if (bindingsParser == null) { bindingsParser = recon.parseConditionalOperator(input, builder); } while (bindingsParser.isCont() && !input.isEmpty()) { bindingsParser = bindingsParser.feed(input); } if (bindingsParser.isDone()) { step = 2; } else if (bindingsParser.isError()) { return bindingsParser.asError(); } } if (step == 2) { if (input.isCont()) { c = input.head(); if (c == '>') { // leading '=' consumed by ComparisonOperatorParser input = input.step(); step = 3; } else { return bindingsParser; } } else if (input.isDone()) { return bindingsParser; } } if (step == 3) { if (templateParser == null) { templateParser = recon.parseConditionalOperator(input, null); } while (templateParser.isCont() && !input.isEmpty()) { templateParser = templateParser.feed(input); } if (templateParser.isDone()) { final V bindings = bindingsParser.bind(); final V template = templateParser.bind(); return done(recon.lambda(bindings, template)); } else if (templateParser.isError()) { return templateParser.asError(); } } if (input.isError()) { return error(input.trap()); } return new LambdaFuncParser<I, V>(recon, builder, bindingsParser, templateParser, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) { return parse(input, recon, builder, null, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/LambdaFuncWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class LambdaFuncWriter<I, V> extends Writer<Object, Object> { final ReconWriter<I, V> recon; final V bindings; final V template; final Writer<?, ?> part; final int step; LambdaFuncWriter(ReconWriter<I, V> recon, V bindings, V template, Writer<?, ?> part, int step) { this.recon = recon; this.bindings = bindings; this.template = template; this.part = part; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.recon, this.bindings, this.template, this.part, this.step); } static <I, V> int sizeOf(ReconWriter<I, V> recon, V bindings, V template) { int size = 0; size += recon.sizeOfPrimary(bindings); size += 4; // " => " size += recon.sizeOfValue(template); return size; } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V bindings, V template, Writer<?, ?> part, int step) { if (step == 1) { if (part == null) { part = recon.writePrimary(bindings, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 2; } else if (part.isError()) { return part.asError(); } } if (step == 2 && output.isCont()) { output = output.write(' '); step = 3; } if (step == 3 && output.isCont()) { output = output.write('='); step = 4; } if (step == 4 && output.isCont()) { output = output.write('>'); step = 5; } if (step == 5 && output.isCont()) { output = output.write(' '); step = 6; } if (step == 6) { if (part == null) { part = recon.writeValue(template, output); } else { part = part.pull(output); } if (part.isDone()) { return done(); } else if (part.isError()) { return part.asError(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new LambdaFuncWriter<I, V>(recon, bindings, template, part, step); } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V bindings, V template) { return write(output, recon, bindings, template, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/LiteralParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.util.Builder; final class LiteralParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final Builder<I, V> builder; final Parser<V> valueParser; final int step; LiteralParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> valueParser, int step) { this.recon = recon; this.builder = builder; this.valueParser = valueParser; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.builder, this.valueParser, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> valueParser, int step) { int c = 0; if (step == 1) { while (input.isCont()) { c = input.head(); if (Recon.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == '(') { input = input.step(); step = 4; } else if (c == '{') { if (builder == null) { builder = recon.recordBuilder(); } valueParser = recon.parseRecord(input, builder); step = 3; } else if (c == '[') { if (builder == null) { builder = recon.recordBuilder(); } valueParser = recon.parseMarkup(input, builder); step = 3; } else if (Recon.isIdentStartChar(c)) { valueParser = recon.parseIdent(input); step = 2; } else if (c == '"' || c == '\'') { valueParser = recon.parseString(input); step = 2; } else if (c == '-' || c >= '0' && c <= '9') { valueParser = recon.parseNumber(input); step = 2; } else if (c == '%') { valueParser = recon.parseData(input); step = 2; } else if (c == '$') { valueParser = recon.parseSelector(input); step = 2; } else if (builder == null) { return done(recon.extant()); } else { return done(builder.bind()); } } else if (input.isDone()) { if (builder == null) { return done(recon.extant()); } else { return done(builder.bind()); } } } if (step == 2) { while (valueParser.isCont() && !input.isEmpty()) { valueParser = valueParser.feed(input); } if (valueParser.isDone()) { if (builder == null) { builder = recon.valueBuilder(); } builder.add(recon.item(valueParser.bind())); return done(builder.bind()); } else if (valueParser.isError()) { return valueParser.asError(); } } if (step == 3) { while (valueParser.isCont() && !input.isEmpty()) { valueParser = valueParser.feed(input); } if (valueParser.isDone()) { return done(builder.bind()); } else if (valueParser.isError()) { return valueParser.asError(); } } if (step == 4) { if (valueParser == null) { valueParser = recon.parseBlockExpression(input); } while (valueParser.isCont() && !input.isEmpty()) { valueParser = valueParser.feed(input); } if (valueParser.isDone()) { step = 5; } else if (valueParser.isError()) { return valueParser.asError(); } } if (step == 5) { while (input.isCont()) { c = input.head(); if (Recon.isWhitespace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == ')') { input = input.step(); if (builder == null) { builder = recon.valueBuilder(); } builder.add(recon.item(valueParser.bind())); return done(builder.bind()); } else { return error(Diagnostic.expected(')', input)); } } else if (input.isDone()) { return error(Diagnostic.expected(')', input)); } } if (input.isError()) { return error(input.trap()); } return new LiteralParser<I, V>(recon, builder, valueParser, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) { return parse(input, recon, builder, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/LiteralSelectorWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class LiteralSelectorWriter<I, V> extends Writer<Object, Object> { final ReconWriter<I, V> recon; final I item; final V then; final Writer<?, ?> part; final int step; LiteralSelectorWriter(ReconWriter<I, V> recon, I item, V then, Writer<?, ?> part, int step) { this.recon = recon; this.item = item; this.then = then; this.part = part; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.recon, this.item, this.then, this.part, this.step); } static <I, V> int sizeOf(ReconWriter<I, V> recon, I item, V then) { int size = 0; if (recon.precedence(item) < recon.precedence(recon.item(then))) { size += 1; // '(' size += recon.sizeOfItem(item); size += 1; // ')' } else { size += recon.sizeOfItem(item); } size += recon.sizeOfThen(then); return size; } @SuppressWarnings("unchecked") static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, I item, V then, Writer<?, ?> part, int step) { if (step == 1) { if (recon.precedence(item) < recon.precedence(recon.item(then))) { if (output.isCont()) { output = output.write('('); step = 2; } } else { step = 2; } } if (step == 2) { if (part == null) { part = recon.writeItem(item, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 3; } else if (part.isError()) { return part.asError(); } } if (step == 3) { if (recon.precedence(item) < recon.precedence(recon.item(then))) { if (output.isCont()) { output = output.write(')'); step = 4; } } else { step = 4; } } if (step == 4) { return (Writer<Object, Object>) recon.writeThen(then, output); } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new LiteralSelectorWriter<I, V>(recon, item, then, part, step); } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, I item, V then) { return write(output, recon, item, then, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/MarkupParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.util.Builder; final class MarkupParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final Builder<I, V> builder; final Output<V> textOutput; final Parser<V> valueParser; final int step; MarkupParser(ReconParser<I, V> recon, Builder<I, V> builder, Output<V> textOutput, Parser<V> valueParser, int step) { this.recon = recon; this.builder = builder; this.textOutput = textOutput; this.valueParser = valueParser; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.builder, this.textOutput, this.valueParser, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder, Output<V> textOutput, Parser<V> valueParser, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (c == '[') { input = input.step(); step = 2; } else { return error(Diagnostic.expected('[', input)); } } else if (input.isDone()) { return error(Diagnostic.expected('[', input)); } } do { if (step == 2) { while (input.isCont()) { c = input.head(); if (c != '@' && c != '[' && c != '\\' && c != ']' && c != '{' && c != '}') { input = input.step(); if (textOutput == null) { textOutput = recon.textOutput(); } textOutput.write(c); } else { break; } } if (input.isCont()) { if (c == ']') { input = input.step(); if (builder == null) { builder = recon.recordBuilder(); } if (textOutput != null) { builder.add(recon.item(textOutput.bind())); } return done(builder.bind()); } else if (c == '@') { if (builder == null) { builder = recon.recordBuilder(); } if (textOutput != null) { builder.add(recon.item(textOutput.bind())); textOutput = null; } valueParser = recon.parseInlineItem(input); step = 3; } else if (c == '{') { if (builder == null) { builder = recon.recordBuilder(); } if (textOutput != null) { builder.add(recon.item(textOutput.bind())); textOutput = null; } valueParser = recon.parseRecord(input, builder); step = 4; } else if (c == '[') { if (builder == null) { builder = recon.recordBuilder(); } if (textOutput != null) { builder.add(recon.item(textOutput.bind())); textOutput = null; } valueParser = recon.parseMarkup(input, builder); step = 4; } else if (c == '\\') { input = input.step(); step = 5; } else { return error(Diagnostic.unexpected(input)); } } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 3) { while (valueParser.isCont() && !input.isEmpty()) { valueParser = valueParser.feed(input); } if (valueParser.isDone()) { builder.add(recon.item(valueParser.bind())); valueParser = null; step = 2; continue; } else if (valueParser.isError()) { return valueParser; } } if (step == 4) { while (valueParser.isCont() && !input.isEmpty()) { valueParser = valueParser.feed(input); } if (valueParser.isDone()) { valueParser = null; step = 2; continue; } else if (valueParser.isError()) { return valueParser; } } if (step == 5) { if (input.isCont()) { c = input.head(); if (textOutput == null) { textOutput = recon.textOutput(); } if (c == '"' || c == '$' || c == '\'' || c == '/' || c == '@' || c == '[' || c == '\\' || c == ']' || c == '{' || c == '}') { input = input.step(); textOutput.write(c); step = 2; } else if (c == 'b') { input = input.step(); textOutput.write('\b'); step = 2; } else if (c == 'f') { input = input.step(); textOutput.write('\f'); step = 2; } else if (c == 'n') { input = input.step(); textOutput.write('\n'); step = 2; } else if (c == 'r') { input = input.step(); textOutput.write('\r'); step = 2; } else if (c == 't') { input = input.step(); textOutput.write('\t'); step = 2; } else { return error(Diagnostic.expected("escape character", input)); } continue; } else if (input.isDone()) { return error(Diagnostic.expected("escape character", input)); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new MarkupParser<I, V>(recon, builder, textOutput, valueParser, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) { return parse(input, recon, builder, null, null, 1); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon) { return parse(input, recon, null, null, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/MarkupTextWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Base16; import swim.codec.Output; import swim.codec.Utf8; import swim.codec.Writer; import swim.codec.WriterException; final class MarkupTextWriter extends Writer<Object, Object> { final String text; final int index; final int escape; final int step; MarkupTextWriter(String text, int index, int escape, int step) { this.text = text; this.index = index; this.escape = escape; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.text, this.index, this.escape, this.step); } static int sizeOf(String text) { int size = 0; for (int i = 0, n = text.length(); i < n; i = text.offsetByCodePoints(i, 1)) { final int c = text.codePointAt(i); if (c == '$' || c == '@' || c == '[' || c == '\\' || c == ']' || c == '{' || c == '}' || c == '\b' || c == '\f' || c == '\n' || c == '\r' || c == '\t') { size += 2; } else if (c < 0x20) { size += 6; } else { size += Utf8.sizeOf(c); } } return size; } static Writer<Object, Object> write(Output<?> output, String text, int index, int escape, int step) { final int length = text.length(); while (output.isCont()) { if (step == 1) { if (index < length) { final int c = text.codePointAt(index); index = text.offsetByCodePoints(index, 1); if (c == '$' || c == '@' || c == '[' || c == '\\' || c == ']' || c == '{' || c == '}') { output = output.write('\\'); escape = c; step = 2; } else if (c == '\b') { output = output.write('\\'); escape = 'b'; step = 2; } else if (c == '\f') { output = output.write('\\'); escape = 'f'; step = 2; } else if (c == '\n') { output = output.write('\\'); escape = 'n'; step = 2; } else if (c == '\r') { output = output.write('\\'); escape = 'r'; step = 2; } else if (c == '\t') { output = output.write('\\'); escape = 't'; step = 2; } else if (c < 0x20) { output = output.write('\\'); escape = c; step = 3; } else { output = output.write(c); } } else { return done(); } } else if (step == 2) { output = output.write(escape); escape = 0; step = 1; } else if (step == 3) { output = output.write('u'); step = 4; } else if (step == 4) { output = output.write(Base16.uppercase().encodeDigit((escape >>> 12) & 0xf)); step = 5; } else if (step == 5) { output = output.write(Base16.uppercase().encodeDigit((escape >>> 8) & 0xf)); step = 6; } else if (step == 6) { output = output.write(Base16.uppercase().encodeDigit((escape >>> 4) & 0xf)); step = 7; } else if (step == 7) { output = output.write(Base16.uppercase().encodeDigit(escape & 0xf)); escape = 0; step = 1; } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new MarkupTextWriter(text, index, escape, step); } static Writer<Object, Object> write(Output<?> output, String text) { return write(output, text, 0, 0, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/MultiplicativeOperatorParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.util.Builder; final class MultiplicativeOperatorParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final Builder<I, V> builder; final Parser<V> lhsParser; final String operator; final Parser<V> rhsParser; final int step; MultiplicativeOperatorParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> lhsParser, String operator, Parser<V> rhsParser, int step) { this.recon = recon; this.builder = builder; this.lhsParser = lhsParser; this.operator = operator; this.rhsParser = rhsParser; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.builder, this.lhsParser, this.operator, this.rhsParser, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> lhsParser, String operator, Parser<V> rhsParser, int step) { int c = 0; do { if (step == 1) { if (lhsParser == null) { lhsParser = recon.parsePrefixOperator(input, builder); } while (lhsParser.isCont() && !input.isEmpty()) { lhsParser = lhsParser.feed(input); } if (lhsParser.isDone()) { step = 2; } else if (lhsParser.isError()) { return lhsParser.asError(); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Recon.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == '*') { input = input.step(); operator = "*"; step = 3; } else if (c == '/') { input = input.step(); operator = "/"; step = 3; } else if (c == '%') { input = input.step(); operator = "%"; step = 3; } else { return lhsParser; } } else if (input.isDone()) { return lhsParser; } } if (step == 3) { if (rhsParser == null) { rhsParser = recon.parsePrefixOperator(input, builder); } while (rhsParser.isCont() && !input.isEmpty()) { rhsParser = rhsParser.feed(input); } if (rhsParser.isDone()) { final V lhs = lhsParser.bind(); final V rhs = rhsParser.bind(); if ("*".equals(operator)) { lhsParser = done(recon.times(lhs, rhs)); } else if ("/".equals(operator)) { lhsParser = done(recon.divide(lhs, rhs)); } else if ("%".equals(operator)) { lhsParser = done(recon.modulo(lhs, rhs)); } else { return error(Diagnostic.message(operator, input)); } rhsParser = null; operator = null; step = 2; continue; } else if (rhsParser.isError()) { return rhsParser.asError(); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new MultiplicativeOperatorParser<I, V>(recon, builder, lhsParser, operator, rhsParser, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) { return parse(input, recon, builder, null, null, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/NumberParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import java.math.BigInteger; import swim.codec.Base16; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; final class NumberParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final int sign; final long value; final int mode; final int step; NumberParser(ReconParser<I, V> recon, int sign, long value, int mode, int step) { this.recon = recon; this.sign = sign; this.value = value; this.mode = mode; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.sign, this.value, this.mode, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, int sign, long value, int mode, int step) { int c = 0; if (step == 1) { while (input.isCont()) { c = input.head(); if (Recon.isWhitespace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == '-') { input = input.step(); sign = -1; } step = 2; } else if (input.isDone()) { return error(Diagnostic.expected("number", input)); } } if (step == 2) { if (input.isCont()) { c = input.head(); if (c == '0') { input = input.step(); step = 4; } else if (c >= '1' && c <= '9') { input = input.step(); value = sign * (c - '0'); step = 3; } else { return error(Diagnostic.expected("digit", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("digit", input)); } } if (step == 3) { while (input.isCont()) { c = input.head(); if (c >= '0' && c <= '9') { final long newValue = 10 * value + sign * (c - '0'); if (value >> 63 == newValue >> 63) { value = newValue; input = input.step(); } else { return BigIntegerParser.parse(input, recon, sign, BigInteger.valueOf(value)); } } else { break; } } if (input.isCont()) { step = 4; } else if (input.isDone()) { return done(recon.num(value)); } } if (step == 4) { if (input.isCont()) { c = input.head(); if (mode > 0 && c == '.' || mode > 1 && (c == 'E' || c == 'e')) { return DecimalParser.parse(input, recon, sign, value, mode); } else if (c == 'x' && sign > 0 && value == 0L) { input = input.step(); return HexadecimalParser.parse(input, recon); } else { return done(recon.num(value)); } } else if (input.isDone()) { return done(recon.num(value)); } } if (input.isError()) { return error(input.trap()); } return new NumberParser<I, V>(recon, sign, value, mode, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon) { return parse(input, recon, 1, 0L, 2, 1); } static <I, V> Parser<V> parseDecimal(Input input, ReconParser<I, V> recon) { return parse(input, recon, 1, 0L, 1, 1); } static <I, V> Parser<V> parseInteger(Input input, ReconParser<I, V> recon) { return parse(input, recon, 1, 0L, 0, 1); } } final class BigIntegerParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final int sign; final BigInteger value; BigIntegerParser(ReconParser<I, V> recon, int sign, BigInteger value) { this.recon = recon; this.sign = sign; this.value = value; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.sign, this.value); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, int sign, BigInteger value) { while (input.isCont()) { final int c = input.head(); if (c >= '0' && c <= '9') { input = input.step(); value = BigInteger.TEN.multiply(value).add(BigInteger.valueOf(sign * (c - '0'))); } else { break; } } if (!input.isEmpty()) { return done(recon.num(value)); } return new BigIntegerParser<I, V>(recon, sign, value); } } final class DecimalParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final StringBuilder builder; final int mode; final int step; DecimalParser(ReconParser<I, V> recon, StringBuilder builder, int mode, int step) { this.recon = recon; this.builder = builder; this.mode = mode; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.builder, this.mode, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, StringBuilder builder, int mode, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (c == '.') { input = input.step(); builder.appendCodePoint(c); step = 2; } else if (mode > 1 && (c == 'E' || c == 'e')) { input = input.step(); builder.appendCodePoint(c); step = 5; } else { return error(Diagnostic.expected("decimal or exponent", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("decimal or exponent", input)); } } if (step == 2) { if (input.isCont()) { c = input.head(); if (c >= '0' && c <= '9') { input = input.step(); builder.appendCodePoint(c); step = 3; } else { return error(Diagnostic.expected("digit", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("digit", input)); } } if (step == 3) { while (input.isCont()) { c = input.head(); if (c >= '0' && c <= '9') { input = input.step(); builder.appendCodePoint(c); } else { break; } } if (input.isCont()) { if (mode > 1) { step = 4; } else { return done(recon.num(builder.toString())); } } else if (input.isDone()) { return done(recon.num(builder.toString())); } } if (step == 4) { c = input.head(); if (c == 'E' || c == 'e') { input = input.step(); builder.appendCodePoint(c); step = 5; } else { return done(recon.num(builder.toString())); } } if (step == 5) { if (input.isCont()) { c = input.head(); if (c == '+' || c == '-') { input = input.step(); builder.appendCodePoint(c); } step = 6; } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 6) { if (input.isCont()) { c = input.head(); if (c >= '0' && c <= '9') { input = input.step(); builder.appendCodePoint(c); step = 7; } else { return error(Diagnostic.expected("digit", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("digit", input)); } } if (step == 7) { while (input.isCont()) { c = input.head(); if (c >= '0' && c <= '9') { input = input.step(); builder.appendCodePoint(c); } else { break; } } if (!input.isEmpty()) { return done(recon.num(builder.toString())); } } if (input.isError()) { return error(input.trap()); } return new DecimalParser<I, V>(recon, builder, mode, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, int sign, long value, int mode) { final StringBuilder builder = new StringBuilder(); if (sign < 0 && value == 0L) { builder.append('-').append('0'); } else { builder.append(value); } return parse(input, recon, builder, mode, 1); } } final class HexadecimalParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final long value; final int size; HexadecimalParser(ReconParser<I, V> recon, long value, int size) { this.recon = recon; this.value = value; this.size = size; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.value, this.size); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, long value, int size) { int c = 0; while (input.isCont()) { c = input.head(); if (Base16.isDigit(c)) { input = input.step(); value = (value << 4) | Base16.decodeDigit(c); size += 1; } else { break; } } if (!input.isEmpty()) { if (size > 0) { if (size <= 8) { return done(recon.uint32((int) value)); } else { return done(recon.uint64(value)); } } else { return error(Diagnostic.expected("hex digit", input)); } } if (input.isError()) { return error(input.trap()); } return new HexadecimalParser<I, V>(recon, value, size); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon) { return parse(input, recon, 0L, 0); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/OrOperatorParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Input; import swim.codec.Parser; import swim.util.Builder; final class OrOperatorParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final Builder<I, V> builder; final Parser<V> lhsParser; final Parser<V> rhsParser; final int step; OrOperatorParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> lhsParser, Parser<V> rhsParser, int step) { this.recon = recon; this.builder = builder; this.lhsParser = lhsParser; this.rhsParser = rhsParser; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.builder, this.lhsParser, this.rhsParser, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> lhsParser, Parser<V> rhsParser, int step) { int c = 0; do { if (step == 1) { if (lhsParser == null) { lhsParser = recon.parseAndOperator(input, builder); } while (lhsParser.isCont() && !input.isEmpty()) { lhsParser = lhsParser.feed(input); } if (lhsParser.isDone()) { step = 2; } else if (lhsParser.isError()) { return lhsParser.asError(); } } if (step == 2) { if (input.isCont()) { c = input.head(); if (c == '|') { // first '|' consumed by BitwiseOrOperatorParser input = input.step(); step = 3; } else { return lhsParser; } } else if (input.isDone()) { return lhsParser; } } if (step == 3) { if (rhsParser == null) { rhsParser = recon.parseAndOperator(input, builder); } while (rhsParser.isCont() && !input.isEmpty()) { rhsParser = rhsParser.feed(input); } if (rhsParser.isDone()) { final V lhs = lhsParser.bind(); final V rhs = rhsParser.bind(); lhsParser = done(recon.or(lhs, rhs)); rhsParser = null; step = 2; continue; } else if (rhsParser.isError()) { return rhsParser.asError(); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new OrOperatorParser<I, V>(recon, builder, lhsParser, rhsParser, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) { return parse(input, recon, builder, null, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/PrefixOperatorParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.util.Builder; final class PrefixOperatorParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final Builder<I, V> builder; final String operator; final Parser<V> rhsParser; final int step; PrefixOperatorParser(ReconParser<I, V> recon, Builder<I, V> builder, String operator, Parser<V> rhsParser, int step) { this.recon = recon; this.builder = builder; this.operator = operator; this.rhsParser = rhsParser; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.builder, this.operator, this.rhsParser, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder, String operator, Parser<V> rhsParser, int step) { int c = 0; if (step == 1) { while (input.isCont()) { c = input.head(); if (Recon.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == '!') { input = input.step(); operator = "!"; } else if (c == '~') { input = input.step(); operator = "~"; } else if (c == '-') { input = input.step(); operator = "-"; } else if (c == '+') { input = input.step(); operator = "+"; } else { return recon.parseInvokeOperator(input, builder); } step = 2; } else if (input.isDone()) { return recon.parseInvokeOperator(input, builder); } } if (step == 2) { if (rhsParser == null) { rhsParser = recon.parsePrefixOperator(input, builder); } while (rhsParser.isCont() && !input.isEmpty()) { rhsParser = rhsParser.feed(input); } if (rhsParser.isDone()) { final V operand = rhsParser.bind(); if (!recon.isDistinct(operand)) { return error(Diagnostic.expected("value", input)); } else if ("!".equals(operator)) { return done(recon.not(operand)); } else if ("~".equals(operator)) { return done(recon.bitwiseNot(operand)); } else if ("-".equals(operator)) { return done(recon.negative(operand)); } else if ("+".equals(operator)) { return done(recon.positive(operand)); } else { return error(Diagnostic.message(operator, input)); } } else if (rhsParser.isError()) { return rhsParser.asError(); } } if (input.isError()) { return error(input.trap()); } return new PrefixOperatorParser<I, V>(recon, builder, operator, rhsParser, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) { return parse(input, recon, builder, null, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/PrefixOperatorWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Output; import swim.codec.Unicode; import swim.codec.Utf8; import swim.codec.Writer; import swim.codec.WriterException; final class PrefixOperatorWriter<I, V> extends Writer<Object, Object> { final ReconWriter<I, V> recon; final String operator; final I rhs; final int precedence; final Writer<?, ?> part; final int step; PrefixOperatorWriter(ReconWriter<I, V> recon, String operator, I rhs, int precedence, Writer<?, ?> part, int step) { this.recon = recon; this.operator = operator; this.rhs = rhs; this.precedence = precedence; this.part = part; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.recon, this.operator, this.rhs, this.precedence, this.part, this.step); } static <I, V> int sizeOf(ReconWriter<I, V> recon, String operator, I rhs, int precedence) { int size = 0; size += Utf8.sizeOf(operator); if (recon.precedence(rhs) < precedence) { size += 1; // '(' size += recon.sizeOfItem(rhs); size += 1; // ')' } else { size += recon.sizeOfItem(rhs); } return size; } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, String operator, I rhs, int precedence, Writer<?, ?> part, int step) { if (step == 1) { if (part == null) { part = Unicode.writeString(operator, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 2; } else if (part.isError()) { return part.asError(); } } if (step == 2) { if (recon.precedence(rhs) < precedence) { if (output.isCont()) { output = output.write('('); step = 3; } } else { step = 3; } } if (step == 3) { if (part == null) { part = recon.writeItem(rhs, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 4; } else if (part.isError()) { return part.asError(); } } if (step == 4) { if (recon.precedence(rhs) < precedence) { if (output.isCont()) { output = output.write(')'); return done(); } } else { return done(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new PrefixOperatorWriter<I, V>(recon, operator, rhs, precedence, part, step); } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, String operator, I rhs, int precedence) { return write(output, recon, operator, rhs, precedence, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/PrimaryParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.util.Builder; final class PrimaryParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final Builder<I, V> builder; final Parser<V> exprParser; final int step; PrimaryParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> exprParser, int step) { this.recon = recon; this.builder = builder; this.exprParser = exprParser; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.builder, this.exprParser, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> exprParser, int step) { int c = 0; if (step == 1) { while (input.isCont()) { c = input.head(); if (Recon.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == '(') { input = input.step(); step = 3; } else { step = 2; } } else if (input.isDone()) { step = 2; } } if (step == 2) { if (exprParser == null) { exprParser = recon.parseLiteral(input, builder); } while (exprParser.isCont() && !input.isEmpty()) { exprParser = exprParser.feed(input); } if (exprParser.isDone()) { return exprParser; } else if (exprParser.isError()) { return exprParser.asError(); } } if (step == 3) { if (exprParser == null) { exprParser = recon.parseBlockExpression(input, builder); } while (exprParser.isCont() && !input.isEmpty()) { exprParser = exprParser.feed(input); } if (exprParser.isDone()) { step = 4; } else if (exprParser.isError()) { return exprParser.asError(); } } do { if (step == 4) { while (input.isCont()) { c = input.head(); if (Recon.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == ',') { input = input.step(); if (exprParser != null) { if (builder == null) { builder = recon.recordBuilder(); builder.add(recon.item(exprParser.bind())); } exprParser = null; } step = 5; } else if (c == ')') { input = input.step(); if (exprParser != null) { return exprParser; } else { return done(builder.bind()); } } else { return error(Diagnostic.expected(')', input)); } } else if (input.isDone()) { return error(Diagnostic.expected(')', input)); } } if (step == 5) { if (exprParser == null) { exprParser = recon.parseBlockExpression(input, builder); } while (exprParser.isCont() && !input.isEmpty()) { exprParser = exprParser.feed(input); } if (exprParser.isDone()) { exprParser = null; step = 4; continue; } else if (exprParser.isError()) { return exprParser.asError(); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new PrimaryParser<I, V>(recon, builder, exprParser, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) { return parse(input, recon, builder, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/PrimaryWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import java.util.Iterator; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class PrimaryWriter<I, V> extends Writer<Object, Object> { final ReconWriter<I, V> recon; final Iterator<I> items; final boolean inParens; final boolean first; final I item; final I next; final Writer<?, ?> part; final int step; PrimaryWriter(ReconWriter<I, V> recon, Iterator<I> items, boolean inParens, boolean first, I item, I next, Writer<?, ?> part, int step) { this.recon = recon; this.items = items; this.inParens = inParens; this.first = first; this.item = item; this.next = next; this.part = part; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.recon, this.items, this.inParens, this.first, this.item, this.next, this.part, this.step); } static <I, V> int sizeOf(ReconWriter<I, V> recon, Iterator<I> items) { int size = 0; boolean inParens = false; boolean first = true; I next = null; while (next != null || items.hasNext()) { final I item; if (next == null) { item = items.next(); } else { item = next; next = null; } if (items.hasNext()) { next = items.next(); } if (!inParens && !first) { size += 1; // ' ' } if (recon.isAttr(item)) { if (inParens) { size += 1; // ')' inParens = false; } size += recon.sizeOfItem(item); first = false; } else if (inParens) { if (!first) { size += 1; // ',' } else { first = false; } size += recon.sizeOfBlockItem(item); } else if (recon.isValue(item) && !recon.isRecord(item) && (!first && next == null || next != null && recon.isAttr(next))) { size += recon.sizeOfItem(item); } else { size += 1; // '(' size += recon.sizeOfItem(item); inParens = true; first = false; } } if (inParens) { size += 1; // ')' } return size; } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, Iterator<I> items, boolean inParens, boolean first, I item, I next, Writer<?, ?> part, int step) { do { if (step == 1) { if (next == null && !items.hasNext()) { step = 5; break; } else { if (next == null) { item = items.next(); } else { item = next; next = null; } if (items.hasNext()) { next = items.next(); } step = 2; } } if (step == 2 && output.isCont()) { if (!inParens && !first) { output = output.write(' '); } step = 3; } if (step == 3 && output.isCont()) { if (recon.isAttr(item)) { if (inParens) { output = output.write(')'); inParens = false; } part = recon.writeItem(item, output); first = false; step = 4; } else if (inParens) { if (!first) { output = output.write(','); } else { first = false; } part = recon.writeBlockItem(item, output); step = 4; } else if (recon.isValue(item) && !recon.isRecord(item) && (!first && next == null || next != null && recon.isAttr(next))) { part = recon.writeItem(item, output); step = 4; } else { output = output.write('('); part = recon.writeItem(item, output); inParens = true; first = false; step = 4; } } if (step == 4) { part = part.pull(output); if (part.isDone()) { part = null; step = 1; continue; } else if (part.isError()) { return part.asError(); } } break; } while (true); if (step == 5) { if (inParens) { if (output.isCont()) { output = output.write(')'); return done(); } } else { return done(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new PrimaryWriter<I, V>(recon, items, inParens, first, item, next, part, step); } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, Iterator<I> items) { return write(output, recon, items, false, true, null, null, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/Recon.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Decoder; import swim.codec.Encoder; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Unicode; import swim.codec.Utf8; import swim.codec.Writer; import swim.structure.Data; import swim.structure.Form; import swim.structure.Item; import swim.structure.Value; /** * Factory for constructing Recon parsers and writers. */ public final class Recon { private Recon() { // stub } static boolean isSpace(int c) { return c == 0x20 || c == 0x9; } static boolean isNewline(int c) { return c == 0xa || c == 0xd; } static boolean isWhitespace(int c) { return isSpace(c) || isNewline(c); } static boolean isIdentStartChar(int c) { return c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= 0xc0 && c <= 0xd6 || c >= 0xd8 && c <= 0xf6 || c >= 0xf8 && c <= 0x2ff || c >= 0x370 && c <= 0x37d || c >= 0x37f && c <= 0x1fff || c >= 0x200c && c <= 0x200d || c >= 0x2070 && c <= 0x218f || c >= 0x2c00 && c <= 0x2fef || c >= 0x3001 && c <= 0xd7ff || c >= 0xf900 && c <= 0xfdcf || c >= 0xfdf0 && c <= 0xfffd || c >= 0x10000 && c <= 0xeffff; } static boolean isIdentChar(int c) { return c == '-' || c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c == 0xb7 || c >= 0xc0 && c <= 0xd6 || c >= 0xd8 && c <= 0xf6 || c >= 0xf8 && c <= 0x37d || c >= 0x37f && c <= 0x1fff || c >= 0x200c && c <= 0x200d || c >= 0x203f && c <= 0x2040 || c >= 0x2070 && c <= 0x218f || c >= 0x2c00 && c <= 0x2fef || c >= 0x3001 && c <= 0xd7ff || c >= 0xf900 && c <= 0xfdcf || c >= 0xfdf0 && c <= 0xfffd || c >= 0x10000 && c <= 0xeffff; } private static ReconParser<Item, Value> structureParser; private static ReconWriter<Item, Value> structureWriter; public static ReconParser<Item, Value> structureParser() { if (structureParser == null) { structureParser = new ReconStructureParser(); } return structureParser; } public static ReconWriter<Item, Value> structureWriter() { if (structureWriter == null) { structureWriter = new ReconStructureWriter(); } return structureWriter; } public static Value parse(String recon) { return structureParser().parseBlockString(recon); } public static Parser<Value> parser() { return structureParser().blockParser(); } public static int sizeOf(Item item) { return structureWriter().sizeOfItem(item); } public static int sizeOfBlock(Item item) { return structureWriter().sizeOfBlockItem(item); } public static Writer<?, ?> write(Item item, Output<?> output) { return structureWriter().writeItem(item, output); } public static Writer<?, ?> writeBlock(Item item, Output<?> output) { return structureWriter().writeBlockItem(item, output); } public static String toString(Item item) { final Output<String> output = Unicode.stringOutput(); write(item, output); return output.bind(); } public static String toBlockString(Item item) { final Output<String> output = Unicode.stringOutput(); writeBlock(item, output); return output.bind(); } public static Data toData(Item item) { final Output<Data> output = Utf8.encodedOutput(Data.output()); write(item, output); return output.bind(); } public static Data toBlockData(Item item) { final Output<Data> output = Utf8.encodedOutput(Data.output()); writeBlock(item, output); return output.bind(); } public static <T> Parser<T> formParser(Form<T> form) { return new ReconFormParser<T>(structureParser(), form); } public static <T> Decoder<T> formDecoder(Form<T> form) { return Utf8.decodedParser(formParser(form)); } public static <T> Writer<T, T> formWriter(Form<T> form) { return new ReconFormWriter<T>(structureWriter(), form); } public static <T> Encoder<T, T> formEncoder(Form<T> form) { return Utf8.encodedWriter(formWriter(form)); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/ReconFormParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Input; import swim.codec.Parser; import swim.structure.Form; import swim.structure.Item; import swim.structure.Value; final class ReconFormParser<T> extends Parser<T> { final ReconParser<Item, Value> recon; final Form<T> form; final Parser<Value> parser; ReconFormParser(ReconParser<Item, Value> recon, Form<T> form, Parser<Value> parser) { this.recon = recon; this.form = form; this.parser = parser; } ReconFormParser(ReconParser<Item, Value> recon, Form<T> form) { this(recon, form, null); } @Override public Parser<T> feed(Input input) { return parse(input, this.recon, this.form, this.parser); } static <T> Parser<T> parse(Input input, ReconParser<Item, Value> recon, Form<T> form, Parser<Value> parser) { if (parser == null) { parser = recon.parseBlock(input); } else { parser = parser.feed(input); } if (parser.isDone()) { final Value value = parser.bind(); return done(form.cast(value)); } else if (parser.isError()) { return parser.asError(); } return new ReconFormParser<T>(recon, form, parser); } static <T> Parser<T> parse(Input input, ReconParser<Item, Value> recon, Form<T> form) { return parse(input, recon, form, null); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/ReconFormWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Output; import swim.codec.Writer; import swim.structure.Form; import swim.structure.Item; import swim.structure.Value; final class ReconFormWriter<T> extends Writer<T, T> { final ReconWriter<Item, Value> recon; final Form<T> form; final T object; final Writer<?, ?> part; ReconFormWriter(ReconWriter<Item, Value> recon, Form<T> form, T object, Writer<?, ?> part) { this.recon = recon; this.form = form; this.object = object; this.part = part; } ReconFormWriter(ReconWriter<Item, Value> recon, Form<T> form) { this(recon, form, null, null); } @Override public Writer<T, T> feed(T object) { return new ReconFormWriter<T>(recon, form, object, null); } @Override public Writer<T, T> pull(Output<?> output) { return write(output, this.recon, this.form, this.object, this.part); } static <T> Writer<T, T> write(Output<?> output, ReconWriter<Item, Value> recon, Form<T> form, T object, Writer<?, ?> part) { if (output == null) { return done(); } if (part == null) { final Value value = form.mold(object).toValue(); part = recon.writeValue(value, output); } else { part = part.pull(output); } if (part.isDone()) { return done(object); } else if (part.isError()) { return part.asError(); } return new ReconFormWriter<T>(recon, form, object, part); } static <T> Writer<T, T> write(Output<T> output, ReconWriter<Item, Value> recon, Form<T> form, T object) { return write(output, recon, form, object, null); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/ReconParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import java.math.BigInteger; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Unicode; import swim.util.Builder; /** * Factory for constructing Recon parsers and parse trees. */ public abstract class ReconParser<I, V> { public abstract boolean isDistinct(V value); public abstract I item(V value); public abstract V value(I item); public abstract I attr(V key, V value); public abstract I attr(V key); public abstract I slot(V key, V value); public abstract I slot(V key); public abstract Builder<I, V> valueBuilder(); public abstract Builder<I, V> recordBuilder(); public abstract Output<V> dataOutput(); public abstract Output<V> textOutput(); public abstract V ident(V value); public abstract V num(int value); public abstract V num(long value); public abstract V num(float value); public abstract V num(double value); public abstract V num(BigInteger value); public abstract V num(String value); public abstract V uint32(int value); public abstract V uint64(long value); public abstract V bool(boolean value); public abstract V selector(); public abstract V extant(); public abstract V absent(); public abstract V conditional(V ifTerm, V thenTerm, V elseTerm); public abstract V or(V lhs, V rhs); public abstract V and(V lhs, V rhs); public abstract V bitwiseOr(V lhs, V rhs); public abstract V bitwiseXor(V lhs, V rhs); public abstract V bitwiseAnd(V lhs, V rhs); public abstract V lt(V lhs, V rhs); public abstract V le(V lhs, V rhs); public abstract V eq(V lhs, V rhs); public abstract V ne(V lhs, V rhs); public abstract V ge(V lhs, V rhs); public abstract V gt(V lhs, V rhs); public abstract V plus(V lhs, V rhs); public abstract V minus(V lhs, V rhs); public abstract V times(V lhs, V rhs); public abstract V divide(V lhs, V rhs); public abstract V modulo(V lhs, V rhs); public abstract V not(V rhs); public abstract V bitwiseNot(V rhs); public abstract V negative(V rhs); public abstract V positive(V rhs); public abstract V invoke(V func, V args); public abstract V lambda(V bindings, V template); public abstract V get(V selector, V key); public abstract V getAttr(V selector, V key); public abstract I getItem(V selector, V index); public abstract V children(V selector); public abstract V descendants(V selector); public abstract V keys(V selector); public abstract V values(V selector); public abstract V filter(V selector, V predicate); public Parser<V> parseBlock(Input input) { return BlockParser.parse(input, this); } public Parser<I> parseAttr(Input input) { return AttrParser.parse(input, this); } public Parser<V> parseBlockItem(Input input) { return BlockItemParser.parse(input, this); } public Parser<V> parseInlineItem(Input input) { return InlineItemParser.parse(input, this); } public Parser<V> parseRecord(Input input, Builder<I, V> builder) { return RecordParser.parse(input, this, builder); } public Parser<V> parseRecord(Input input) { return RecordParser.parse(input, this); } public Parser<V> parseMarkup(Input input, Builder<I, V> builder) { return MarkupParser.parse(input, this, builder); } public Parser<V> parseMarkup(Input input) { return MarkupParser.parse(input, this); } public Parser<V> parseData(Input input) { return DataParser.parse(input, this); } public Parser<V> parseIdent(Input input) { return IdentParser.parse(input, this); } public Parser<V> parseString(Input input) { return StringParser.parse(input, this); } public Parser<V> parseNumber(Input input) { return NumberParser.parse(input, this); } public Parser<V> parseInteger(Input input) { return NumberParser.parseInteger(input, this); } public Parser<V> parseBlockExpression(Input input, Builder<I, V> builder) { return parseLambdaFunc(input, builder); } public Parser<V> parseBlockExpression(Input input) { return parseLambdaFunc(input, null); } public Parser<V> parseLambdaFunc(Input input, Builder<I, V> builder) { return LambdaFuncParser.parse(input, this, builder); } public Parser<V> parseConditionalOperator(Input input, Builder<I, V> builder) { return ConditionalOperatorParser.parse(input, this, builder); } public Parser<V> parseOrOperator(Input input, Builder<I, V> builder) { return OrOperatorParser.parse(input, this, builder); } public Parser<V> parseAndOperator(Input input, Builder<I, V> builder) { return AndOperatorParser.parse(input, this, builder); } public Parser<V> parseBitwiseOrOperator(Input input, Builder<I, V> builder) { return BitwiseOrOperatorParser.parse(input, this, builder); } public Parser<V> parseBitwiseXorOperator(Input input, Builder<I, V> builder) { return BitwiseXorOperatorParser.parse(input, this, builder); } public Parser<V> parseBitwiseAndOperator(Input input, Builder<I, V> builder) { return BitwiseAndOperatorParser.parse(input, this, builder); } public Parser<V> parseComparisonOperator(Input input, Builder<I, V> builder) { return ComparisonOperatorParser.parse(input, this, builder); } public Parser<V> parseAttrExpression(Input input, Builder<I, V> builder) { return AttrExpressionParser.parse(input, this, builder); } public Parser<V> parseAdditiveOperator(Input input, Builder<I, V> builder) { return AdditiveOperatorParser.parse(input, this, builder); } public Parser<V> parseMultiplicativeOperator(Input input, Builder<I, V> builder) { return MultiplicativeOperatorParser.parse(input, this, builder); } public Parser<V> parsePrefixOperator(Input input, Builder<I, V> builder) { return PrefixOperatorParser.parse(input, this, builder); } public Parser<V> parseInvokeOperator(Input input, Builder<I, V> builder) { return InvokeOperatorParser.parse(input, this, builder); } public Parser<V> parsePrimary(Input input, Builder<I, V> builder) { return PrimaryParser.parse(input, this, builder); } public Parser<V> parseLiteral(Input input, Builder<I, V> builder) { return LiteralParser.parse(input, this, builder); } public Parser<V> parseSelector(Input input, Builder<I, V> builder) { return SelectorParser.parse(input, this, builder); } public Parser<V> parseSelector(Input input) { return SelectorParser.parse(input, this, null); } public Parser<V> blockParser() { return new BlockParser<I, V>(this); } public V parseBlockString(String string) { Input input = Unicode.stringInput(string); while (input.isCont() && Recon.isWhitespace(input.head())) { input = input.step(); } Parser<V> parser = parseBlock(input); if (parser.isDone()) { while (input.isCont() && Recon.isWhitespace(input.head())) { input = input.step(); } } if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } else if (input.isError()) { parser = Parser.error(input.trap()); } return parser.bind(); } public V parseNumberString(String string) { Input input = Unicode.stringInput(string); while (input.isCont() && Recon.isWhitespace(input.head())) { input = input.step(); } Parser<V> parser = parseNumber(input); if (parser.isDone()) { while (input.isCont() && Recon.isWhitespace(input.head())) { input = input.step(); } } if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } else if (input.isError()) { parser = Parser.error(input.trap()); } return parser.bind(); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/ReconStructureParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import java.math.BigInteger; import swim.codec.Output; import swim.structure.Attr; import swim.structure.Bool; import swim.structure.Data; import swim.structure.Item; import swim.structure.Num; import swim.structure.Record; import swim.structure.Selector; import swim.structure.Slot; import swim.structure.Text; import swim.structure.Value; import swim.util.Builder; public class ReconStructureParser extends ReconParser<Item, Value> { @Override public boolean isDistinct(Value value) { return value.isDistinct(); } @Override public Item item(Value value) { return value; } @Override public Value value(Item item) { return item.toValue(); } @Override public Item attr(Value key, Value value) { return Attr.of((Text) key, value); } @Override public Item attr(Value key) { return Attr.of((Text) key); } @Override public Item slot(Value key, Value value) { return Slot.of(key, value); } @Override public Item slot(Value key) { return Slot.of(key); } @Override public Builder<Item, Value> valueBuilder() { return Value.builder(); } @SuppressWarnings("unchecked") @Override public Builder<Item, Value> recordBuilder() { return (Builder<Item, Value>) (Builder<?, ?>) Record.create(); } @SuppressWarnings("unchecked") @Override public Output<Value> dataOutput() { return (Output<Value>) (Output<?>) Data.output(); } @SuppressWarnings("unchecked") @Override public Output<Value> textOutput() { return (Output<Value>) (Output<?>) Text.output(); } @Override public Value ident(Value value) { if (value instanceof Text) { final String string = value.stringValue(); if ("true".equals(string)) { return Bool.from(true); } else if ("false".equals(string)) { return Bool.from(false); } } return value; } @Override public Value num(int value) { return Num.from(value); } @Override public Value num(long value) { if ((int) value == value) { return Num.from((int) value); } else { return Num.from(value); } } @Override public Value num(float value) { return Num.from(value); } @Override public Value num(double value) { if ((float) value == value) { return Num.from((float) value); } else { return Num.from(value); } } @Override public Value num(BigInteger value) { return Num.from(value); } @Override public Value num(String value) { return Num.from(Double.parseDouble(value)); } @Override public Value uint32(int value) { return Num.uint32(value); } @Override public Value uint64(long value) { return Num.uint64(value); } @Override public Value bool(boolean value) { return Bool.from(value); } @Override public Value selector() { return Selector.identity(); } @Override public Value extant() { return Value.extant(); } @Override public Value absent() { return Value.absent(); } @Override public Value conditional(Value ifTerm, Value thenTerm, Value elseTerm) { return ifTerm.conditional(thenTerm, elseTerm); } @Override public Value or(Value lhs, Value rhs) { return lhs.or(rhs); } @Override public Value and(Value lhs, Value rhs) { return lhs.and(rhs); } @Override public Value bitwiseOr(Value lhs, Value rhs) { return lhs.bitwiseOr(rhs); } @Override public Value bitwiseXor(Value lhs, Value rhs) { return lhs.bitwiseXor(rhs); } @Override public Value bitwiseAnd(Value lhs, Value rhs) { return lhs.bitwiseAnd(rhs); } @Override public Value lt(Value lhs, Value rhs) { return lhs.lt(rhs); } @Override public Value le(Value lhs, Value rhs) { return lhs.le(rhs); } @Override public Value eq(Value lhs, Value rhs) { return lhs.eq(rhs); } @Override public Value ne(Value lhs, Value rhs) { return lhs.ne(rhs); } @Override public Value ge(Value lhs, Value rhs) { return lhs.ge(rhs); } @Override public Value gt(Value lhs, Value rhs) { return lhs.gt(rhs); } @Override public Value plus(Value lhs, Value rhs) { return lhs.plus(rhs); } @Override public Value minus(Value lhs, Value rhs) { return lhs.minus(rhs); } @Override public Value times(Value lhs, Value rhs) { return lhs.times(rhs); } @Override public Value divide(Value lhs, Value rhs) { return lhs.divide(rhs); } @Override public Value modulo(Value lhs, Value rhs) { return lhs.modulo(rhs); } @Override public Value not(Value rhs) { return rhs.not(); } @Override public Value bitwiseNot(Value rhs) { return rhs.bitwiseNot(); } @Override public Value negative(Value rhs) { return rhs.negative(); } @Override public Value positive(Value rhs) { return rhs.positive(); } @Override public Value invoke(Value func, Value args) { return func.invoke(args).toValue(); } @Override public Value lambda(Value bindings, Value template) { return bindings.lambda(template); } @Override public Value get(Value selector, Value key) { return selector.get(key); } @Override public Value getAttr(Value selector, Value key) { return selector.getAttr((Text) key); } @Override public Item getItem(Value selector, Value index) { return selector.getItem(index.intValue()); } @Override public Value children(Value selector) { return Selector.literal(selector).children(); } @Override public Value descendants(Value selector) { return Selector.literal(selector).descendants(); } @Override public Value keys(Value selector) { return Selector.literal(selector).keys(); } @Override public Value values(Value selector) { return Selector.literal(selector).values(); } @Override public Value filter(Value selector, Value predicate) { return selector.filter(predicate); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/ReconStructureWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import java.util.Iterator; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; import swim.structure.Absent; import swim.structure.Attr; import swim.structure.Bool; import swim.structure.Data; import swim.structure.Expression; import swim.structure.Extant; import swim.structure.Field; import swim.structure.Func; import swim.structure.Item; import swim.structure.Num; import swim.structure.Operator; import swim.structure.Record; import swim.structure.Selector; import swim.structure.Slot; import swim.structure.Text; import swim.structure.Value; import swim.structure.func.BridgeFunc; import swim.structure.func.LambdaFunc; import swim.structure.operator.BinaryOperator; import swim.structure.operator.ConditionalOperator; import swim.structure.operator.InvokeOperator; import swim.structure.operator.UnaryOperator; import swim.structure.selector.ChildrenSelector; import swim.structure.selector.DescendantsSelector; import swim.structure.selector.FilterSelector; import swim.structure.selector.GetAttrSelector; import swim.structure.selector.GetItemSelector; import swim.structure.selector.GetSelector; import swim.structure.selector.IdentitySelector; import swim.structure.selector.KeysSelector; import swim.structure.selector.LiteralSelector; import swim.structure.selector.ValuesSelector; public class ReconStructureWriter extends ReconWriter<Item, Value> { @Override public boolean isField(Item item) { return item instanceof Field; } @Override public boolean isAttr(Item item) { return item instanceof Attr; } @Override public boolean isSlot(Item item) { return item instanceof Slot; } @Override public boolean isValue(Item item) { return item instanceof Value; } @Override public boolean isRecord(Item item) { return item instanceof Record; } @Override public boolean isText(Item item) { return item instanceof Text; } @Override public boolean isNum(Item item) { return item instanceof Num; } @Override public boolean isBool(Item item) { return item instanceof Bool; } @Override public boolean isExpression(Item item) { return item instanceof Expression; } @Override public boolean isExtant(Item item) { return item instanceof Extant; } @Override public Iterator<Item> items(Item item) { return item.iterator(); } @Override public Item item(Value value) { return value; } @Override public Value key(Item item) { return item.key(); } @Override public Value value(Item item) { return item.toValue(); } @Override public String string(Item item) { return item.stringValue(); } @Override public int precedence(Item item) { return item.precedence(); } @Override public int sizeOfItem(Item item) { if (item instanceof Field) { if (item instanceof Attr) { final Attr that = (Attr) item; return sizeOfAttr(that.key(), that.value()); } else if (item instanceof Slot) { final Slot that = (Slot) item; return sizeOfSlot(that.key(), that.value()); } } else if (item instanceof Value) { return sizeOfValue((Value) item); } throw new WriterException("No Recon serialization for " + item); } @Override public Writer<?, ?> writeItem(Item item, Output<?> output) { if (item instanceof Field) { if (item instanceof Attr) { final Attr that = (Attr) item; return writeAttr(that.key(), that.value(), output); } else if (item instanceof Slot) { final Slot that = (Slot) item; return writeSlot(that.key(), that.value(), output); } } else if (item instanceof Value) { return writeValue((Value) item, output); } return Writer.error(new WriterException("No Recon serialization for " + item)); } @Override public int sizeOfValue(Value value) { if (value instanceof Record) { final Record that = (Record) value; return sizeOfRecord(that); } else if (value instanceof Data) { final Data that = (Data) value; return sizeOfData(that.size()); } else if (value instanceof Text) { final Text that = (Text) value; return sizeOfText(that.stringValue()); } else if (value instanceof Num) { final Num that = (Num) value; if (that.isUint32()) { return sizeOfUint32(that.intValue()); } else if (that.isUint64()) { return sizeOfUint64(that.longValue()); } else if (that.isValidInt()) { return sizeOfNum(that.intValue()); } else if (that.isValidLong()) { return sizeOfNum(that.longValue()); } else if (that.isValidFloat()) { return sizeOfNum(that.floatValue()); } else if (that.isValidDouble()) { return sizeOfNum(that.doubleValue()); } else if (that.isValidInteger()) { return sizeOfNum(that.integerValue()); } } else if (value instanceof Bool) { final Bool that = (Bool) value; return sizeOfBool(that.booleanValue()); } else if (value instanceof Selector) { return sizeOfSelector((Selector) value); } else if (value instanceof Operator) { return sizeOfOperator((Operator) value); } else if (value instanceof Func) { return sizeOfFunc((Func) value); } else if (value instanceof Extant) { return sizeOfExtant(); } else if (value instanceof Absent) { return sizeOfAbsent(); } throw new WriterException("No Recon serialization for " + value); } @Override public Writer<?, ?> writeValue(Value value, Output<?> output) { if (value instanceof Record) { final Record that = (Record) value; return writeRecord(that, output); } else if (value instanceof Data) { final Data that = (Data) value; return writeData(that.asByteBuffer(), output); } else if (value instanceof Text) { final Text that = (Text) value; return writeText(that.stringValue(), output); } else if (value instanceof Num) { final Num that = (Num) value; if (that.isUint32()) { return writeUint32(that.intValue(), output); } else if (that.isUint64()) { return writeUint64(that.longValue(), output); } else if (that.isValidInt()) { return writeNum(that.intValue(), output); } else if (that.isValidLong()) { return writeNum(that.longValue(), output); } else if (that.isValidFloat()) { return writeNum(that.floatValue(), output); } else if (that.isValidDouble()) { return writeNum(that.doubleValue(), output); } else if (that.isValidInteger()) { return writeNum(that.integerValue(), output); } } else if (value instanceof Bool) { final Bool that = (Bool) value; return writeBool(that.booleanValue(), output); } else if (value instanceof Selector) { return writeSelector((Selector) value, output); } else if (value instanceof Operator) { return writeOperator((Operator) value, output); } else if (value instanceof Func) { return writeFunc((Func) value, output); } else if (value instanceof Extant) { return writeExtant(output); } else if (value instanceof Absent) { return writeAbsent(output); } return Writer.error(new WriterException("No Recon serialization for " + value)); } public int sizeOfSelector(Selector selector) { if (selector instanceof IdentitySelector) { return sizeOfIdentitySelector(); } else if (selector instanceof LiteralSelector) { final LiteralSelector that = (LiteralSelector) selector; return sizeOfLiteralSelector(that.item(), that.then()); } else if (selector instanceof GetSelector) { final GetSelector that = (GetSelector) selector; return sizeOfGetSelector(that.accessor(), that.then()); } else if (selector instanceof GetAttrSelector) { final GetAttrSelector that = (GetAttrSelector) selector; return sizeOfGetAttrSelector(that.accessor(), that.then()); } else if (selector instanceof GetItemSelector) { final GetItemSelector that = (GetItemSelector) selector; return sizeOfGetItemSelector(that.accessor(), that.then()); } else if (selector instanceof KeysSelector) { final KeysSelector that = (KeysSelector) selector; return sizeOfKeysSelector(that.then()); } else if (selector instanceof ValuesSelector) { final ValuesSelector that = (ValuesSelector) selector; return sizeOfValuesSelector(that.then()); } else if (selector instanceof ChildrenSelector) { final ChildrenSelector that = (ChildrenSelector) selector; return sizeOfChildrenSelector(that.then()); } else if (selector instanceof DescendantsSelector) { final DescendantsSelector that = (DescendantsSelector) selector; return sizeOfDescendantsSelector(that.then()); } else if (selector instanceof FilterSelector) { final FilterSelector that = (FilterSelector) selector; return sizeOfFilterSelector(that.predicate(), that.then()); } throw new WriterException("No Recon serialization for " + selector); } public Writer<?, ?> writeSelector(Selector selector, Output<?> output) { if (selector instanceof IdentitySelector) { return writeIdentitySelector(output); } else if (selector instanceof LiteralSelector) { final LiteralSelector that = (LiteralSelector) selector; return writeLiteralSelector(that.item(), that.then(), output); } else if (selector instanceof GetSelector) { final GetSelector that = (GetSelector) selector; return writeGetSelector(that.accessor(), that.then(), output); } else if (selector instanceof GetAttrSelector) { final GetAttrSelector that = (GetAttrSelector) selector; return writeGetAttrSelector(that.accessor(), that.then(), output); } else if (selector instanceof GetItemSelector) { final GetItemSelector that = (GetItemSelector) selector; return writeGetItemSelector(that.accessor(), that.then(), output); } else if (selector instanceof KeysSelector) { final KeysSelector that = (KeysSelector) selector; return writeKeysSelector(that.then(), output); } else if (selector instanceof ValuesSelector) { final ValuesSelector that = (ValuesSelector) selector; return writeValuesSelector(that.then(), output); } else if (selector instanceof ChildrenSelector) { final ChildrenSelector that = (ChildrenSelector) selector; return writeChildrenSelector(that.then(), output); } else if (selector instanceof DescendantsSelector) { final DescendantsSelector that = (DescendantsSelector) selector; return writeDescendantsSelector(that.then(), output); } else if (selector instanceof FilterSelector) { final FilterSelector that = (FilterSelector) selector; return writeFilterSelector(that.predicate(), that.then(), output); } return Writer.error(new WriterException("No Recon serialization for " + selector)); } public int sizeOfOperator(Operator operator) { if (operator instanceof BinaryOperator) { final BinaryOperator that = (BinaryOperator) operator; return sizeOfInfixOperator(that.operand1(), that.operator(), that.operand2(), that.precedence()); } else if (operator instanceof UnaryOperator) { final UnaryOperator that = (UnaryOperator) operator; return sizeOfPrefixOperator(that.operator(), that.operand(), that.precedence()); } else if (operator instanceof InvokeOperator) { final InvokeOperator that = (InvokeOperator) operator; return sizeOfInvokeOperator(that.func(), that.args()); } else if (operator instanceof ConditionalOperator) { final ConditionalOperator that = (ConditionalOperator) operator; return sizeOfConditionalOperator(that.ifTerm(), that.thenTerm(), that.elseTerm(), that.precedence()); } throw new WriterException("No Recon serialization for " + operator); } public Writer<?, ?> writeOperator(Operator operator, Output<?> output) { if (operator instanceof BinaryOperator) { final BinaryOperator that = (BinaryOperator) operator; return writeInfixOperator(that.operand1(), that.operator(), that.operand2(), that.precedence(), output); } else if (operator instanceof UnaryOperator) { final UnaryOperator that = (UnaryOperator) operator; return writePrefixOperator(that.operator(), that.operand(), that.precedence(), output); } else if (operator instanceof InvokeOperator) { final InvokeOperator that = (InvokeOperator) operator; return writeInvokeOperator(that.func(), that.args(), output); } else if (operator instanceof ConditionalOperator) { final ConditionalOperator that = (ConditionalOperator) operator; return writeConditionalOperator(that.ifTerm(), that.thenTerm(), that.elseTerm(), that.precedence(), output); } return Writer.error(new WriterException("No Recon serialization for " + operator)); } public int sizeOfFunc(Func func) { if (func instanceof LambdaFunc) { final LambdaFunc that = (LambdaFunc) func; return sizeOfLambdaFunc(that.bindings(), that.template()); } else if (func instanceof BridgeFunc) { return 0; } throw new WriterException("No Recon serialization for " + func); } public Writer<?, ?> writeFunc(Func func, Output<?> output) { if (func instanceof LambdaFunc) { final LambdaFunc that = (LambdaFunc) func; return writeLambdaFunc(that.bindings(), that.template(), output); } else if (func instanceof BridgeFunc) { return Writer.done(); } return Writer.error(new WriterException("No Recon serialization for " + func)); } @Override public int sizeOfBlockItem(Item item) { if (item instanceof Field) { return sizeOfItem(item); } else if (item instanceof Value) { return sizeOfBlockValue((Value) item); } throw new WriterException("No Recon serialization for " + item); } @Override public Writer<?, ?> writeBlockItem(Item item, Output<?> output) { if (item instanceof Field) { return writeItem(item, output); } else if (item instanceof Value) { return writeBlockValue((Value) item, output); } return Writer.error(new WriterException("No Recon serialization for " + item)); } @Override public int sizeOfBlockValue(Value value) { if (value instanceof Record) { return sizeOfBlock((Record) value); } return sizeOfValue(value); } @Override public Writer<?, ?> writeBlockValue(Value value, Output<?> output) { if (value instanceof Record) { return writeBlock((Record) value, output); } return writeValue(value, output); } @Override public int sizeOfThen(Value then) { if (then instanceof Selector) { final Selector selector = (Selector) then; if (selector instanceof IdentitySelector) { return sizeOfThenIdentitySelector(); } else if (selector instanceof LiteralSelector) { final LiteralSelector that = (LiteralSelector) selector; return sizeOfThenLiteralSelector(that.item(), that.then()); } else if (selector instanceof GetSelector) { final GetSelector that = (GetSelector) selector; return sizeOfThenGetSelector(that.accessor(), that.then()); } else if (selector instanceof GetAttrSelector) { final GetAttrSelector that = (GetAttrSelector) selector; return sizeOfThenGetAttrSelector(that.accessor(), that.then()); } else if (selector instanceof GetItemSelector) { final GetItemSelector that = (GetItemSelector) selector; return sizeOfThenGetItemSelector(that.accessor(), that.then()); } else if (selector instanceof KeysSelector) { final KeysSelector that = (KeysSelector) selector; return sizeOfThenKeysSelector(that.then()); } else if (selector instanceof ValuesSelector) { final ValuesSelector that = (ValuesSelector) selector; return sizeOfThenValuesSelector(that.then()); } else if (selector instanceof ChildrenSelector) { final ChildrenSelector that = (ChildrenSelector) selector; return sizeOfThenChildrenSelector(that.then()); } else if (selector instanceof DescendantsSelector) { final DescendantsSelector that = (DescendantsSelector) selector; return sizeOfThenDescendantsSelector(that.then()); } else if (selector instanceof FilterSelector) { final FilterSelector that = (FilterSelector) selector; return sizeOfThenFilterSelector(that.predicate(), that.then()); } } throw new WriterException("No Recon serialization for " + then); } @Override public Writer<?, ?> writeThen(Value then, Output<?> output) { if (then instanceof Selector) { final Selector selector = (Selector) then; if (selector instanceof IdentitySelector) { return writeThenIdentitySelector(output); } else if (selector instanceof LiteralSelector) { final LiteralSelector that = (LiteralSelector) selector; return writeThenLiteralSelector(that.item(), that.then(), output); } else if (selector instanceof GetSelector) { final GetSelector that = (GetSelector) selector; return writeThenGetSelector(that.accessor(), that.then(), output); } else if (selector instanceof GetAttrSelector) { final GetAttrSelector that = (GetAttrSelector) selector; return writeThenGetAttrSelector(that.accessor(), that.then(), output); } else if (selector instanceof GetItemSelector) { final GetItemSelector that = (GetItemSelector) selector; return writeThenGetItemSelector(that.accessor(), that.then(), output); } else if (selector instanceof KeysSelector) { final KeysSelector that = (KeysSelector) selector; return writeThenKeysSelector(that.then(), output); } else if (selector instanceof ValuesSelector) { final ValuesSelector that = (ValuesSelector) selector; return writeThenValuesSelector(that.then(), output); } else if (selector instanceof ChildrenSelector) { final ChildrenSelector that = (ChildrenSelector) selector; return writeThenChildrenSelector(that.then(), output); } else if (selector instanceof DescendantsSelector) { final DescendantsSelector that = (DescendantsSelector) selector; return writeThenDescendantsSelector(that.then(), output); } else if (selector instanceof FilterSelector) { final FilterSelector that = (FilterSelector) selector; return writeThenFilterSelector(that.predicate(), that.then(), output); } } return Writer.error(new WriterException("No Recon serialization for " + then)); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/ReconWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import java.math.BigInteger; import java.nio.ByteBuffer; import java.util.Iterator; import swim.codec.Base10; import swim.codec.Base16; import swim.codec.Output; import swim.codec.Unicode; import swim.codec.Writer; /** * Factory for constructing Recon writers. */ public abstract class ReconWriter<I, V> { public abstract boolean isField(I item); public abstract boolean isAttr(I item); public abstract boolean isSlot(I item); public abstract boolean isValue(I item); public abstract boolean isRecord(I item); public abstract boolean isText(I item); public abstract boolean isNum(I item); public abstract boolean isBool(I item); public abstract boolean isExpression(I item); public abstract boolean isExtant(I item); public abstract Iterator<I> items(I item); public abstract I item(V value); public abstract V key(I item); public abstract V value(I item); public abstract String string(I item); public abstract int precedence(I item); public abstract int sizeOfItem(I item); public abstract Writer<?, ?> writeItem(I item, Output<?> output); public abstract int sizeOfValue(V value); public abstract Writer<?, ?> writeValue(V value, Output<?> output); public abstract int sizeOfBlockValue(V value); public abstract Writer<?, ?> writeBlockValue(V value, Output<?> output); public int sizeOfAttr(V key, V value) { return AttrWriter.sizeOf(this, key, value); } public Writer<?, ?> writeAttr(V key, V value, Output<?> output) { return AttrWriter.write(output, this, key, value); } public int sizeOfSlot(V key, V value) { return SlotWriter.sizeOf(this, key, value); } public Writer<?, ?> writeSlot(V key, V value, Output<?> output) { return SlotWriter.write(output, this, key, value); } public abstract int sizeOfBlockItem(I item); public abstract Writer<?, ?> writeBlockItem(I item, Output<?> output); public int sizeOfBlock(Iterator<I> items, boolean inBlock, boolean inMarkup) { return BlockWriter.sizeOf(this, items, inBlock, inMarkup); } public Writer<?, ?> writeBlock(Iterator<I> items, Output<?> output, boolean inBlock, boolean inMarkup) { return BlockWriter.write(output, this, items, inBlock, inMarkup); } public int sizeOfBlock(I item) { final Iterator<I> items = items(item); if (items.hasNext()) { return BlockWriter.sizeOf(this, items, isBlockSafe(items(item)), false); } else { return 2; // "{}" } } public Writer<?, ?> writeBlock(I item, Output<?> output) { final Iterator<I> items = items(item); if (items.hasNext()) { return BlockWriter.write(output, this, items, isBlockSafe(items(item)), false); } else { return Unicode.writeString("{}", output); } } public int sizeOfRecord(I item) { final Iterator<I> items = items(item); if (items.hasNext()) { return BlockWriter.sizeOf(this, items, false, false); } else { return 2; // "{}" } } public Writer<?, ?> writeRecord(I item, Output<?> output) { final Iterator<I> items = items(item); if (items.hasNext()) { return BlockWriter.write(output, this, items, false, false); } else { return Unicode.writeString("{}", output); } } public int sizeOfPrimary(V value) { if (isRecord(item(value))) { final Iterator<I> items = items(item(value)); if (items.hasNext()) { return PrimaryWriter.sizeOf(this, items); } } else if (!isExtant(item(value))) { return sizeOfValue(value); } return 2; // "()" } public Writer<?, ?> writePrimary(V value, Output<?> output) { if (isRecord(item(value))) { final Iterator<I> items = items(item(value)); if (items.hasNext()) { return PrimaryWriter.write(output, this, items); } } else if (!isExtant(item(value))) { return writeValue(value, output); } return Unicode.writeString("()", output); } public boolean isBlockSafe(Iterator<I> items) { while (items.hasNext()) { if (isAttr(items.next())) { return false; } } return true; } public boolean isMarkupSafe(Iterator<I> items) { if (!items.hasNext() || !isAttr(items.next())) { return false; } while (items.hasNext()) { if (isAttr(items.next())) { return false; } } return true; } public int sizeOfMarkupText(I item) { return sizeOfMarkupText(string(item)); } public Writer<?, ?> writeMarkupText(I item, Output<?> output) { return writeMarkupText(string(item), output); } public int sizeOfMarkupText(String text) { return MarkupTextWriter.sizeOf(text); } public Writer<?, ?> writeMarkupText(String text, Output<?> output) { return MarkupTextWriter.write(output, text); } public int sizeOfData(int length) { return DataWriter.sizeOf(length); } public Writer<?, ?> writeData(ByteBuffer value, Output<?> output) { if (value != null) { return DataWriter.write(output, value); } else { return Unicode.writeString("%", output); } } public boolean isIdent(I item) { return isIdent(string(item)); } public boolean isIdent(String value) { final int n = value.length(); if (n == 0 || !Recon.isIdentStartChar(value.codePointAt(0))) { return false; } for (int i = value.offsetByCodePoints(0, 1); i < n; i = value.offsetByCodePoints(i, 1)) { if (!Recon.isIdentChar(value.codePointAt(i))) { return false; } } return true; } public int sizeOfText(String value) { if (isIdent(value)) { return IdentWriter.sizeOf(value); } else { return StringWriter.sizeOf(value); } } public Writer<?, ?> writeText(String value, Output<?> output) { if (isIdent(value)) { return IdentWriter.write(output, value); } else { return StringWriter.write(output, value); } } public int sizeOfNum(int value) { int size = Base10.countDigits(value); if (value < 0) { size += 1; } return size; } public Writer<?, ?> writeNum(int value, Output<?> output) { return Base10.writeInt(value, output); } public int sizeOfNum(long value) { int size = Base10.countDigits(value); if (value < 0L) { size += 1; } return size; } public Writer<?, ?> writeNum(long value, Output<?> output) { return Base10.writeLong(value, output); } public int sizeOfNum(float value) { return Float.toString(value).length(); } public Writer<?, ?> writeNum(float value, Output<?> output) { return Base10.writeFloat(value, output); } public int sizeOfNum(double value) { return Double.toString(value).length(); } public Writer<?, ?> writeNum(double value, Output<?> output) { return Base10.writeDouble(value, output); } public int sizeOfNum(BigInteger value) { return value.toString().length(); } public Writer<?, ?> writeNum(BigInteger value, Output<?> output) { return Unicode.writeString(value, output); } public int sizeOfUint32(int value) { return 10; } public Writer<?, ?> writeUint32(int value, Output<?> output) { return Base16.lowercase().writeIntLiteral(value, output, 8); } public int sizeOfUint64(long value) { return 18; } public Writer<?, ?> writeUint64(long value, Output<?> output) { return Base16.lowercase().writeLongLiteral(value, output, 16); } public int sizeOfBool(boolean value) { return value ? 4 : 5; } public Writer<?, ?> writeBool(boolean value, Output<?> output) { return Unicode.writeString(value ? "true" : "false", output); } public int sizeOfLambdaFunc(V bindings, V template) { return LambdaFuncWriter.sizeOf(this, bindings, template); } public Writer<?, ?> writeLambdaFunc(V bindings, V template, Output<?> output) { return LambdaFuncWriter.write(output, this, bindings, template); } public int sizeOfConditionalOperator(I ifTerm, I thenTerm, I elseTerm, int precedence) { return ConditionalOperatorWriter.sizeOf(this, ifTerm, thenTerm, elseTerm, precedence); } public Writer<?, ?> writeConditionalOperator(I ifTerm, I thenTerm, I elseTerm, int precedence, Output<?> output) { return ConditionalOperatorWriter.write(output, this, ifTerm, thenTerm, elseTerm, precedence); } public int sizeOfInfixOperator(I lhs, String operator, I rhs, int precedence) { return InfixOperatorWriter.sizeOf(this, lhs, operator, rhs, precedence); } public Writer<?, ?> writeInfixOperator(I lhs, String operator, I rhs, int precedence, Output<?> output) { return InfixOperatorWriter.write(output, this, lhs, operator, rhs, precedence); } public int sizeOfPrefixOperator(String operator, I operand, int precedence) { return PrefixOperatorWriter.sizeOf(this, operator, operand, precedence); } public Writer<?, ?> writePrefixOperator(String operator, I operand, int precedence, Output<?> output) { return PrefixOperatorWriter.write(output, this, operator, operand, precedence); } public int sizeOfInvokeOperator(V func, V args) { return InvokeOperatorWriter.sizeOf(this, func, args); } public Writer<?, ?> writeInvokeOperator(V func, V args, Output<?> output) { return InvokeOperatorWriter.write(output, this, func, args); } public abstract int sizeOfThen(V then); public abstract Writer<?, ?> writeThen(V then, Output<?> output); public int sizeOfIdentitySelector() { return 0; } public Writer<?, ?> writeIdentitySelector(Output<?> output) { return Writer.done(); } public int sizeOfThenIdentitySelector() { return 0; } public Writer<?, ?> writeThenIdentitySelector(Output<?> output) { return Writer.done(); } public int sizeOfLiteralSelector(I item, V then) { return LiteralSelectorWriter.sizeOf(this, item, then); } public Writer<?, ?> writeLiteralSelector(I item, V then, Output<?> output) { return LiteralSelectorWriter.write(output, this, item, then); } public int sizeOfThenLiteralSelector(I item, V then) { return 0; } public Writer<?, ?> writeThenLiteralSelector(I item, V then, Output<?> output) { return Writer.done(); } public int sizeOfGetSelector(V key, V then) { return GetSelectorWriter.sizeOf(this, key, then); } public Writer<?, ?> writeGetSelector(V key, V then, Output<?> output) { return GetSelectorWriter.write(output, this, key, then); } public int sizeOfThenGetSelector(V key, V then) { return GetSelectorWriter.sizeOf(this, key, then); } public Writer<?, ?> writeThenGetSelector(V key, V then, Output<?> output) { return GetSelectorWriter.writeThen(output, this, key, then); } public int sizeOfGetAttrSelector(V key, V then) { return GetAttrSelectorWriter.sizeOf(this, key, then); } public Writer<?, ?> writeGetAttrSelector(V key, V then, Output<?> output) { return GetAttrSelectorWriter.write(output, this, key, then); } public int sizeOfThenGetAttrSelector(V key, V then) { return GetAttrSelectorWriter.sizeOf(this, key, then); } public Writer<?, ?> writeThenGetAttrSelector(V key, V then, Output<?> output) { return GetAttrSelectorWriter.writeThen(output, this, key, then); } public int sizeOfGetItemSelector(V index, V then) { return GetItemSelectorWriter.sizeOf(this, index, then); } public Writer<?, ?> writeGetItemSelector(V index, V then, Output<?> output) { return GetItemSelectorWriter.write(output, this, index, then); } public int sizeOfThenGetItemSelector(V index, V then) { return GetItemSelectorWriter.sizeOfThen(this, index, then); } public Writer<?, ?> writeThenGetItemSelector(V index, V then, Output<?> output) { return GetItemSelectorWriter.writeThen(output, this, index, then); } public int sizeOfKeysSelector(V then) { return KeysSelectorWriter.sizeOf(this, then); } public Writer<?, ?> writeKeysSelector(V then, Output<?> output) { return KeysSelectorWriter.write(output, this, then); } public int sizeOfThenKeysSelector(V then) { return KeysSelectorWriter.sizeOf(this, then); } public Writer<?, ?> writeThenKeysSelector(V then, Output<?> output) { return KeysSelectorWriter.writeThen(output, this, then); } public int sizeOfValuesSelector(V then) { return ValuesSelectorWriter.sizeOf(this, then); } public Writer<?, ?> writeValuesSelector(V then, Output<?> output) { return ValuesSelectorWriter.write(output, this, then); } public int sizeOfThenValuesSelector(V then) { return ValuesSelectorWriter.sizeOf(this, then); } public Writer<?, ?> writeThenValuesSelector(V then, Output<?> output) { return ValuesSelectorWriter.writeThen(output, this, then); } public int sizeOfChildrenSelector(V then) { return ChildrenSelectorWriter.sizeOf(this, then); } public Writer<?, ?> writeChildrenSelector(V then, Output<?> output) { return ChildrenSelectorWriter.write(output, this, then); } public int sizeOfThenChildrenSelector(V then) { return ChildrenSelectorWriter.sizeOf(this, then); } public Writer<?, ?> writeThenChildrenSelector(V then, Output<?> output) { return ChildrenSelectorWriter.writeThen(output, this, then); } public int sizeOfDescendantsSelector(V then) { return DescendantsSelectorWriter.sizeOf(this, then); } public Writer<?, ?> writeDescendantsSelector(V then, Output<?> output) { return DescendantsSelectorWriter.write(output, this, then); } public int sizeOfThenDescendantsSelector(V then) { return DescendantsSelectorWriter.sizeOf(this, then); } public Writer<?, ?> writeThenDescendantsSelector(V then, Output<?> output) { return DescendantsSelectorWriter.writeThen(output, this, then); } public int sizeOfFilterSelector(V predicate, V then) { return FilterSelectorWriter.sizeOf(this, predicate, then); } public Writer<?, ?> writeFilterSelector(V predicate, V then, Output<?> output) { return FilterSelectorWriter.write(output, this, predicate, then); } public int sizeOfThenFilterSelector(V predicate, V then) { return FilterSelectorWriter.sizeOfThen(this, predicate, then); } public Writer<?, ?> writeThenFilterSelector(V predicate, V then, Output<?> output) { return FilterSelectorWriter.writeThen(output, this, predicate, then); } public int sizeOfExtant() { return 0; } public Writer<?, ?> writeExtant(Output<?> output) { return Writer.done(); } public int sizeOfAbsent() { return 0; } public Writer<?, ?> writeAbsent(Output<?> output) { return Writer.done(); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/RecordParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.util.Builder; final class RecordParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final Builder<I, V> builder; final Parser<V> keyParser; final Parser<V> valueParser; final int step; RecordParser(ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> keyParser, Parser<V> valueParser, int step) { this.recon = recon; this.builder = builder; this.keyParser = keyParser; this.valueParser = valueParser; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.builder, this.keyParser, this.valueParser, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder, Parser<V> keyParser, Parser<V> valueParser, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (c == '{') { input = input.step(); step = 2; } else { return error(Diagnostic.expected('{', input)); } } else if (input.isDone()) { return error(Diagnostic.expected('{', input)); } } block: do { if (step == 2) { while (input.isCont()) { c = input.head(); if (Recon.isWhitespace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (builder == null) { builder = recon.recordBuilder(); } if (c == '}') { input = input.step(); return done(builder.bind()); } else if (c == '#') { input = input.step(); step = 8; } else { step = 3; } } else if (input.isDone()) { return error(Diagnostic.expected('}', input)); } } if (step == 3) { if (keyParser == null) { keyParser = recon.parseBlockExpression(input); } while (keyParser.isCont() && !input.isEmpty()) { keyParser = keyParser.feed(input); } if (keyParser.isDone()) { step = 4; } else if (keyParser.isError()) { return keyParser; } } if (step == 4) { while (input.isCont()) { c = input.head(); if (Recon.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == ':') { input = input.step(); step = 5; } else { builder.add(recon.item(keyParser.bind())); keyParser = null; step = 7; } } else if (input.isDone()) { return error(Diagnostic.expected('}', input)); } } if (step == 5) { while (input.isCont() && Recon.isSpace(input.head())) { input = input.step(); } if (input.isCont()) { step = 6; } else if (input.isDone()) { builder.add(recon.slot(keyParser.bind())); return done(builder.bind()); } } if (step == 6) { if (valueParser == null) { valueParser = recon.parseBlockExpression(input); } while (valueParser.isCont() && !input.isEmpty()) { valueParser = valueParser.feed(input); } if (valueParser.isDone()) { builder.add(recon.slot(keyParser.bind(), valueParser.bind())); keyParser = null; valueParser = null; step = 7; } else if (valueParser.isError()) { return valueParser; } } if (step == 7) { while (input.isCont()) { c = input.head(); if (Recon.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == ',' || c == ';' || Recon.isNewline(c)) { input = input.step(); step = 2; continue; } else if (c == '#') { input = input.step(); step = 8; } else if (c == '}') { input = input.step(); return done(builder.bind()); } else { return error(Diagnostic.expected("'}', ';', ',', or newline", input)); } } else if (input.isDone()) { return error(Diagnostic.expected('}', input)); } } if (step == 8) { while (input.isCont()) { c = input.head(); if (!Recon.isNewline(c)) { input = input.step(); } else { step = 2; continue block; } } if (input.isDone()) { step = 2; continue; } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new RecordParser<I, V>(recon, builder, keyParser, valueParser, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) { return parse(input, recon, builder, null, null, 1); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon) { return parse(input, recon, null, null, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/SelectorParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.util.Builder; final class SelectorParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final Builder<I, V> builder; final V selector; final Parser<V> valueParser; final int step; SelectorParser(ReconParser<I, V> recon, Builder<I, V> builder, V selector, Parser<V> valueParser, int step) { this.recon = recon; this.builder = builder; this.selector = selector; this.valueParser = valueParser; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.builder, this.selector, this.valueParser, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder, V selector, Parser<V> valueParser, int step) { int c = 0; if (step == 1) { while (input.isCont()) { c = input.head(); if (Recon.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == '$') { input = input.step(); if (selector == null) { selector = recon.selector(); } step = 2; } else if (input.isDone()) { return error(Diagnostic.expected('$', input)); } } if (step == 2) { if (input.isCont()) { c = input.head(); if (c == '[') { input = input.step(); step = 8; } else if (c == '@') { input = input.step(); step = 7; } else if (c == ':') { input = input.step(); step = 6; } else if (c == '*') { input = input.step(); step = 5; } else if (c == '#') { input = input.step(); step = 4; } else { step = 3; } } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } do { if (step == 3) { if (valueParser == null) { valueParser = recon.parseLiteral(input, recon.valueBuilder()); } while (valueParser.isCont() && !input.isEmpty()) { valueParser = valueParser.feed(input); } if (valueParser.isDone()) { selector = recon.get(selector, valueParser.bind()); valueParser = null; step = 10; } else if (valueParser.isError()) { return valueParser.asError(); } } if (step == 4) { if (valueParser == null) { valueParser = recon.parseInteger(input); } while (valueParser.isCont() && !input.isEmpty()) { valueParser = valueParser.feed(input); } if (valueParser.isDone()) { selector = recon.value(recon.getItem(selector, valueParser.bind())); valueParser = null; step = 10; } else if (valueParser.isError()) { return valueParser.asError(); } } if (step == 5) { if (input.isCont()) { c = input.head(); if (c == ':') { input = input.step(); selector = recon.keys(selector); step = 10; } else if (c == '*') { input = input.step(); selector = recon.descendants(selector); step = 10; } else { selector = recon.children(selector); step = 10; } } else if (input.isDone()) { selector = recon.children(selector); step = 10; } } if (step == 6) { if (input.isCont()) { c = input.head(); if (c == '*') { input = input.step(); selector = recon.values(selector); step = 10; } else { return error(Diagnostic.expected('*', input)); } } else if (input.isDone()) { return error(Diagnostic.expected('*', input)); } } if (step == 7) { if (valueParser == null) { valueParser = recon.parseIdent(input); } while (valueParser.isCont() && !input.isEmpty()) { valueParser = valueParser.feed(input); } if (valueParser.isDone()) { selector = recon.getAttr(selector, valueParser.bind()); valueParser = null; step = 10; } else if (valueParser.isError()) { return valueParser.asError(); } } if (step == 8) { if (valueParser == null) { valueParser = recon.parseBlockExpression(input); } while (valueParser.isCont() && !input.isEmpty()) { valueParser = valueParser.feed(input); } if (valueParser.isDone()) { step = 9; } else if (valueParser.isError()) { return valueParser.asError(); } } if (step == 9) { while (input.isCont()) { c = input.head(); if (Recon.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == ']') { input = input.step(); selector = recon.filter(selector, valueParser.bind()); valueParser = null; step = 10; } else { return error(Diagnostic.expected(']', input)); } } else if (input.isDone()) { return error(Diagnostic.expected(']', input)); } } if (step == 10) { if (input.isCont()) { c = input.head(); if (c == '[') { input = input.step(); step = 8; continue; } else if (c == '#') { input = input.step(); step = 4; continue; } else if (c == '.') { input = input.step(); step = 11; } else if (builder != null) { builder.add(recon.item(selector)); return done(builder.bind()); } else { return done(selector); } } else if (input.isDone()) { if (builder != null) { builder.add(recon.item(selector)); return done(builder.bind()); } else { return done(selector); } } } if (step == 11) { if (input.isCont()) { c = input.head(); if (c == '@') { input = input.step(); step = 7; continue; } else if (c == ':') { input = input.step(); step = 6; continue; } else if (c == '*') { input = input.step(); step = 5; continue; } else { step = 3; continue; } } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new SelectorParser<I, V>(recon, builder, selector, valueParser, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Builder<I, V> builder) { return parse(input, recon, builder, null, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/SlotWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class SlotWriter<I, V> extends Writer<Object, Object> { final ReconWriter<I, V> recon; final V key; final V value; final Writer<?, ?> part; final int step; SlotWriter(ReconWriter<I, V> recon, V key, V value, Writer<?, ?> part, int step) { this.recon = recon; this.key = key; this.value = value; this.part = part; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.recon, this.key, this.value, this.part, this.step); } static <I, V> int sizeOf(ReconWriter<I, V> recon, V key, V value) { int size = 0; size += recon.sizeOfValue(key); size += 1; // ':' if (!recon.isExtant(recon.item(value))) { size += recon.sizeOfValue(value); } return size; } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V key, V value, Writer<?, ?> part, int step) { if (step == 1) { if (part == null) { part = recon.writeValue(key, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 2; } else if (part.isError()) { return part.asError(); } } if (step == 2 && output.isCont()) { output = output.write(':'); if (recon.isExtant(recon.item(value))) { return done(); } else { step = 3; } } if (step == 3) { if (part == null) { part = recon.writeValue(value, output); } else { part = part.pull(output); } if (part.isDone()) { return done(); } else if (part.isError()) { return part.asError(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new SlotWriter<I, V>(recon, key, value, part, step); } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V key, V value) { return write(output, recon, key, value, null, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/StringParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Base16; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; final class StringParser<I, V> extends Parser<V> { final ReconParser<I, V> recon; final Output<V> output; final int quote; final int code; final int step; StringParser(ReconParser<I, V> recon, Output<V> output, int quote, int code, int step) { this.recon = recon; this.output = output; this.quote = quote; this.code = code; this.step = step; } @Override public Parser<V> feed(Input input) { return parse(input, this.recon, this.output, this.quote, this.code, this.step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Output<V> output, int quote, int code, int step) { int c = 0; if (step == 1) { while (input.isCont()) { c = input.head(); if (Recon.isWhitespace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if ((c == '"' || c == '\'') && (quote == c || quote == 0)) { input = input.step(); if (output == null) { output = recon.textOutput(); } quote = c; step = 2; } else { return error(Diagnostic.expected("string", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("string", input)); } } string: do { if (step == 2) { while (input.isCont()) { c = input.head(); if (c >= 0x20 && c != quote && c != '\\') { input = input.step(); output = output.write(c); } else { break; } } if (input.isCont()) { if (c == quote) { input = input.step(); return done(output.bind()); } else if (c == '\\') { input = input.step(); step = 3; } else { return error(Diagnostic.expected(quote, input)); } } else if (input.isDone()) { return error(Diagnostic.expected(quote, input)); } } if (step == 3) { if (input.isCont()) { c = input.head(); if (c == '"' || c == '$' || c == '\'' || c == '/' || c == '@' || c == '[' || c == '\\' || c == ']' || c == '{' || c == '}') { input = input.step(); output = output.write(c); step = 2; continue; } else if (c == 'b') { input = input.step(); output = output.write('\b'); step = 2; continue; } else if (c == 'f') { input = input.step(); output = output.write('\f'); step = 2; continue; } else if (c == 'n') { input = input.step(); output = output.write('\n'); step = 2; continue; } else if (c == 'r') { input = input.step(); output = output.write('\r'); step = 2; continue; } else if (c == 't') { input = input.step(); output = output.write('\t'); step = 2; continue; } else if (c == 'u') { input = input.step(); step = 4; } else { return error(Diagnostic.expected("escape character", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("escape character", input)); } } if (step >= 4) { do { if (input.isCont()) { c = input.head(); if (Base16.isDigit(c)) { input = input.step(); code = 16 * code + Base16.decodeDigit(c); if (step <= 6) { step += 1; continue; } else { output = output.write(code); code = 0; step = 2; continue string; } } else { return error(Diagnostic.expected("hex digit", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("hex digit", input)); } break; } while (true); } break; } while (true); if (input.isError()) { return error(input.trap()); } return new StringParser<I, V>(recon, output, quote, code, step); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon) { return parse(input, recon, null, 0, 0, 1); } static <I, V> Parser<V> parse(Input input, ReconParser<I, V> recon, Output<V> output) { return parse(input, recon, output, 0, 0, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/StringWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Base16; import swim.codec.Output; import swim.codec.Utf8; import swim.codec.Writer; import swim.codec.WriterException; final class StringWriter extends Writer<Object, Object> { final String string; final int index; final int escape; final int step; StringWriter(String string, int index, int escape, int step) { this.string = string; this.index = index; this.escape = escape; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.string, this.index, this.escape, this.step); } static int sizeOf(String string) { int size = 0; size += 1; // '"'; for (int i = 0, n = string.length(); i < n; i = string.offsetByCodePoints(i, 1)) { final int c = string.codePointAt(i); if (c == '"' || c == '\\' || c == '\b' || c == '\f' || c == '\n' || c == '\r' || c == '\t') { size += 2; } else if (c < 0x20) { size += 6; } else { size += Utf8.sizeOf(c); } } size += 1; // '"'; return size; } static Writer<Object, Object> write(Output<?> output, String string, int index, int escape, int step) { if (step == 1 && output.isCont()) { output = output.write('"'); step = 2; } final int length = string.length(); while (step >= 2 && step <= 8 && output.isCont()) { if (step == 2) { if (index < length) { final int c = string.codePointAt(index); index = string.offsetByCodePoints(index, 1); if (c == '"' || c == '\\') { output = output.write('\\'); escape = c; step = 3; } else if (c == '\b') { output = output.write('\\'); escape = 'b'; step = 3; } else if (c == '\f') { output = output.write('\\'); escape = 'f'; step = 3; } else if (c == '\n') { output = output.write('\\'); escape = 'n'; step = 3; } else if (c == '\r') { output = output.write('\\'); escape = 'r'; step = 3; } else if (c == '\t') { output = output.write('\\'); escape = 't'; step = 3; } else if (c < 0x20) { output = output.write('\\'); escape = c; step = 4; } else { output = output.write(c); } } else { step = 9; break; } } else if (step == 3) { output = output.write(escape); escape = 0; step = 2; } else if (step == 4) { output = output.write('u'); step = 5; } else if (step == 5) { output = output.write(Base16.uppercase().encodeDigit((escape >>> 12) & 0xf)); step = 6; } else if (step == 6) { output = output.write(Base16.uppercase().encodeDigit((escape >>> 8) & 0xf)); step = 7; } else if (step == 7) { output = output.write(Base16.uppercase().encodeDigit((escape >>> 4) & 0xf)); step = 8; } else if (step == 8) { output = output.write(Base16.uppercase().encodeDigit(escape & 0xf)); escape = 0; step = 2; } } if (step == 9 && output.isCont()) { output = output.write('"'); return done(); } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new StringWriter(string, index, escape, step); } static Writer<Object, Object> write(Output<?> output, String string) { return write(output, string, 0, 0, 1); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/ValuesSelectorWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.recon; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class ValuesSelectorWriter<I, V> extends Writer<Object, Object> { final ReconWriter<I, V> recon; final V then; final int step; ValuesSelectorWriter(ReconWriter<I, V> recon, V then, int step) { this.recon = recon; this.then = then; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.recon, this.then, this.step); } static <I, V> int sizeOf(ReconWriter<I, V> recon, V then) { int size = 3; // ('$' | '.') ':' '*' size += recon.sizeOfThen(then); return size; } @SuppressWarnings("unchecked") static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V then, int step) { if (step == 1 && output.isCont()) { output = output.write('$'); step = 3; } else if (step == 2 && output.isCont()) { output = output.write('.'); step = 3; } if (step == 3 && output.isCont()) { output = output.write(':'); step = 4; } if (step == 4 && output.isCont()) { output = output.write('*'); return (Writer<Object, Object>) recon.writeThen(then, output); } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new ValuesSelectorWriter<I, V>(recon, then, step); } static <I, V> Writer<Object, Object> write(Output<?> output, ReconWriter<I, V> recon, V then) { return write(output, recon, then, 1); } static <I, V> Writer<Object, Object> writeThen(Output<?> output, ReconWriter<I, V> recon, V then) { return write(output, recon, then, 2); } }
0
java-sources/ai/swim/swim-recon/3.10.0/swim
java-sources/ai/swim/swim-recon/3.10.0/swim/recon/package-info.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /** * Record Notation (Recon) codec. * * <h2>Grammar</h2> * * <pre> * SP ::= #x20 | #x9 * * NL ::= #xA | #xD * * WS ::= SP | NL * * Char ::= [#x1-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] * * NameStartChar ::= * [A-Z] | "_" | [a-z] | * [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | * [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | * [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | * [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] * * NameChar ::= NameStartChar | '-' | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040] * * MarkupChar ::= Char - ('\\' | '@' | '{' | '}' | '[' | ']') * * StringChar ::= Char - ('"' | '\\' | '@' | '{' | '}' | '[' | ']' | '\b' | '\f' | '\n' | '\r' | '\t') * * CharEscape ::= '\\' ('"' | '\\' | '/' | '@' | '{' | '}' | '[' | ']' | 'b' | 'f' | 'n' | 'r' | 't') * * Base64Char ::= [A-Za-z0-9+/] * * Block ::= WS* Slots WS* * * Attr ::= '@' (Ident | String) ('(' Block ')')? * * Slots ::= Slot SP* ((',' | ';' | NL) WS* Slots)? * * Slot ::= BlockItem (SP* ':' SP* BlockItem?)? * * BlockItem ::= Literal SP* (Attr SP* BlockItem?)? | Attr SP* BlockItem? | Comment * * InlineItem ::= Attr (Record | Markup)? | Record | Markup * * Literal ::= Record | Markup | Data | Ident | String | Num | Bool | Selector * * Record ::= '{' Block '}' * * Markup ::= '[' (MarkupChar* | CharEscape | InlineItem)* ']' * * Data ::= '%' (Base64Char{4})* (Base64Char Base64Char ((Base64Char '=') | ('=' '=')))? * * Ident ::= NameStartChar NameChar* * * String ::= ('"' (StringChar* | CharEscape)* '"') | ('\'' (StringChar* | CharEscape)* '\'') * * Num ::= '-'? (([1-9] [0-9]*) | [0-9]) ('.' [0-9]+)? (('E' | 'e') ('+' | '-')? [0-9]+)? * * Bool ::= 'true' | 'false' * * Comment ::= '#' [^\n]* * * * Selector ::= '$' (Literal | '*:' | ':*' | '*' | '**' | '#' Integer | Filter) * ('.' (Literal | '*:' | ':*' | '*' | '**') | '#' Integer | Filter | '(' Block ')')* * * Filter ::= '[' BlockExpression ']' * * * BlockExpression ::= LambdaFunc * * LambdaFunc ::= ConditionalOperator (SP* '=&gt;' SP* ConditionalOperator)? * * ConditionalOperator ::= OrOperator SP* ('?' SP* ConditionalOperator SP* ':' SP* ConditionalOperator)? * * OrOperator ::= AndOperator SP* ('||' SP* AndOperator)* * * AndOperator ::= BitwiseOrOperator SP* ('&amp;&amp;' SP* BitwiseOrOperator)* * * BitwiseOrOperator ::= BitwiseXorOperator SP* ('|' SP* BitwiseXorOperator)* * * BitwiseXorOperator ::= BitwiseAndOperator SP* ('^' SP* BitwiseAndOperator)* * * BitwiseAndOperator ::= ComparisonOperator SP* ('&amp;' SP* ComparisonOperator)* * * ComparisonOperator ::= AttrExpression SP* (('&lt;' | '&lt;=' | '==' | '&gt;=' | '&gt;') SP* AttrExpression)? * * AttrExpression ::= AdditiveOperator SP* (Attr SP* AttrExpression?)? | Attr SP* AttrExpression? * * AdditiveOperator ::= MultiplicativeOperator SP* (('+' | '-') SP* MultiplicativeOperator)* * * MultiplicativeOperator ::= PrefixOperator SP* (('*' | '/' | '%') SP* PrefixOperator)* * * PrefixOperator ::= InvokeOperator SP* | ('!' | '~' | '-' | '+') SP* PrefixOperator * * InvokeOperator ::= Primary ('(' Block ')')* * * Primary ::= Literal | '(' BlockExpression (',' BlockExpression)* ')' * </pre> */ package swim.recon;
0
java-sources/ai/swim/swim-remote
java-sources/ai/swim/swim-remote/3.10.0/module-info.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /** * Web Agent remote router. */ module swim.remote { requires transitive swim.io.warp; requires transitive swim.runtime; requires transitive swim.kernel; exports swim.remote; provides swim.kernel.Kernel with swim.remote.RemoteKernel; }
0
java-sources/ai/swim/swim-remote/3.10.0/swim
java-sources/ai/swim/swim-remote/3.10.0/swim/remote/RemoteCredentials.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.remote; import swim.api.auth.Credentials; import swim.structure.Value; import swim.uri.Uri; public final class RemoteCredentials implements Credentials { final Uri requestUri; final Uri fromUri; final Value claims; public RemoteCredentials(Uri requestUri, Uri fromUri, Value claims) { this.requestUri = requestUri; this.fromUri = fromUri; this.claims = claims; } @Override public Uri requestUri() { return this.requestUri; } @Override public Uri fromUri() { return this.fromUri; } @Override public Value claims() { return this.claims; } }
0
java-sources/ai/swim/swim-remote/3.10.0/swim
java-sources/ai/swim/swim-remote/3.10.0/swim/remote/RemoteHost.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.remote; import java.net.InetSocketAddress; import java.security.Principal; import java.security.cert.Certificate; import java.util.Collection; import java.util.Iterator; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import swim.api.Downlink; import swim.api.auth.Identity; import swim.api.policy.Policy; import swim.api.policy.PolicyDirective; import swim.collections.FingerTrieSeq; import swim.collections.HashTrieMap; import swim.collections.HashTrieSet; import swim.concurrent.PullContext; import swim.concurrent.PullRequest; import swim.concurrent.Schedule; import swim.concurrent.Stage; import swim.http.HttpRequest; import swim.http.HttpResponse; import swim.io.IpSocket; import swim.io.warp.WarpSocket; import swim.io.warp.WarpSocketContext; import swim.runtime.AbstractTierBinding; import swim.runtime.HostBinding; import swim.runtime.HostContext; import swim.runtime.LinkBinding; import swim.runtime.NodeBinding; import swim.runtime.PartBinding; import swim.runtime.PushRequest; import swim.runtime.TierContext; import swim.runtime.UplinkError; import swim.runtime.WarpBinding; import swim.store.StoreBinding; import swim.structure.Value; import swim.uri.Uri; import swim.uri.UriAuthority; import swim.uri.UriHost; import swim.uri.UriPath; import swim.uri.UriPort; import swim.uri.UriScheme; import swim.util.HashGenCacheMap; import swim.warp.AuthRequest; import swim.warp.AuthedResponse; import swim.warp.CommandMessage; import swim.warp.DeauthRequest; import swim.warp.DeauthedResponse; import swim.warp.Envelope; import swim.warp.EventMessage; import swim.warp.LaneAddressed; import swim.warp.LinkAddressed; import swim.warp.LinkRequest; import swim.warp.LinkedResponse; import swim.warp.SyncRequest; import swim.warp.SyncedResponse; import swim.warp.UnlinkRequest; import swim.warp.UnlinkedResponse; import swim.ws.WsClose; import swim.ws.WsControl; import swim.ws.WsPing; import swim.ws.WsPong; public class RemoteHost extends AbstractTierBinding implements HostBinding, WarpSocket { protected HostContext hostContext; protected WarpSocketContext warpSocketContext; final Uri requestUri; final Uri baseUri; Uri remoteUri; volatile int flags; volatile Identity remoteIdentity; volatile HashTrieMap<Uri, HashTrieMap<Uri, RemoteWarpDownlink>> downlinks; volatile HashTrieMap<Uri, HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>>> uplinks; final HashGenCacheMap<Uri, Uri> resolveCache; public RemoteHost(Uri requestUri, Uri baseUri) { this.requestUri = requestUri; this.baseUri = baseUri; this.downlinks = HashTrieMap.empty(); this.uplinks = HashTrieMap.empty(); this.resolveCache = new HashGenCacheMap<Uri, Uri>(URI_RESOLUTION_CACHE_SIZE); } public RemoteHost(Uri baseUri) { this(Uri.empty(), baseUri); } @Override public final TierContext tierContext() { return this.hostContext; } @Override public final PartBinding part() { return this.hostContext.part(); } @Override public final HostBinding hostWrapper() { return this; } @SuppressWarnings("unchecked") @Override public <T> T unwrapHost(Class<T> hostClass) { if (hostClass.isAssignableFrom(getClass())) { return (T) this; } else { return this.hostContext.unwrapHost(hostClass); } } @Override public final HostContext hostContext() { return this.hostContext; } @Override public void setHostContext(HostContext hostContext) { this.hostContext = hostContext; } @Override public WarpSocketContext warpSocketContext() { return this.warpSocketContext; } public void setWarpSocketContext(WarpSocketContext warpSocketContext) { this.warpSocketContext = warpSocketContext; } @Override public long idleTimeout() { return -1; // default timeout } @Override public Uri meshUri() { return this.hostContext.meshUri(); } @Override public Value partKey() { return this.hostContext.partKey(); } @Override public Uri hostUri() { return this.hostContext.hostUri(); } @Override public Policy policy() { return this.hostContext.policy(); } @Override public Schedule schedule() { return this.hostContext.schedule(); } @Override public Stage stage() { return this.hostContext.stage(); } @Override public StoreBinding store() { return this.hostContext.store(); } @Override public boolean isConnected() { final WarpSocketContext warpSocketContext = this.warpSocketContext; return warpSocketContext != null && warpSocketContext.isConnected(); } @Override public boolean isRemote() { return true; } @Override public boolean isSecure() { final WarpSocketContext warpSocketContext = this.warpSocketContext; return warpSocketContext != null && warpSocketContext.isSecure(); } public String securityProtocol() { final WarpSocketContext warpSocketContext = this.warpSocketContext; if (warpSocketContext != null) { return warpSocketContext.securityProtocol(); } else { return null; } } public String cipherSuite() { final WarpSocketContext warpSocketContext = this.warpSocketContext; if (warpSocketContext != null) { return warpSocketContext.cipherSuite(); } else { return null; } } public InetSocketAddress localAddress() { final WarpSocketContext warpSocketContext = this.warpSocketContext; if (warpSocketContext != null) { return warpSocketContext.localAddress(); } else { return null; } } public Identity localIdentity() { return null; // TODO } public Principal localPrincipal() { final WarpSocketContext warpSocketContext = this.warpSocketContext; if (warpSocketContext != null) { return warpSocketContext.localPrincipal(); } else { return null; } } public Collection<Certificate> localCertificates() { final WarpSocketContext warpSocketContext = this.warpSocketContext; if (warpSocketContext != null) { return warpSocketContext.localCertificates(); } else { return FingerTrieSeq.empty(); } } public InetSocketAddress remoteAddress() { final WarpSocketContext warpSocketContext = this.warpSocketContext; if (warpSocketContext != null) { return warpSocketContext.remoteAddress(); } else { return null; } } public Identity remoteIdentity() { return this.remoteIdentity; } public Principal remotePrincipal() { final WarpSocketContext warpSocketContext = this.warpSocketContext; if (warpSocketContext != null) { return warpSocketContext.remotePrincipal(); } else { return null; } } public Collection<Certificate> remoteCertificates() { final WarpSocketContext warpSocketContext = this.warpSocketContext; if (warpSocketContext != null) { return warpSocketContext.remoteCertificates(); } else { return FingerTrieSeq.empty(); } } @Override public boolean isPrimary() { return (this.flags & PRIMARY) != 0; } @Override public void setPrimary(boolean isPrimary) { int oldFlags; int newFlags; do { oldFlags = this.flags; newFlags = oldFlags | PRIMARY; } while (oldFlags != newFlags && !FLAGS.compareAndSet(this, oldFlags, newFlags)); } @Override public boolean isReplica() { return (this.flags & REPLICA) != 0; } @Override public void setReplica(boolean isReplica) { int oldFlags; int newFlags; do { oldFlags = this.flags; newFlags = oldFlags | REPLICA; } while (oldFlags != newFlags && !FLAGS.compareAndSet(this, oldFlags, newFlags)); } @Override public boolean isMaster() { return (this.flags & MASTER) != 0; } @Override public boolean isSlave() { return (this.flags & SLAVE) != 0; } @Override public void didBecomeMaster() { int oldFlags; int newFlags; do { oldFlags = this.flags; newFlags = oldFlags & ~SLAVE | MASTER; } while (oldFlags != newFlags && !FLAGS.compareAndSet(this, oldFlags, newFlags)); } @Override public void didBecomeSlave() { int oldFlags; int newFlags; do { oldFlags = this.flags; newFlags = oldFlags & ~MASTER | SLAVE; } while (oldFlags != newFlags && !FLAGS.compareAndSet(this, oldFlags, newFlags)); } RemoteWarpDownlink createWarpDownlink(Uri remoteNodeUri, Uri nodeUri, Uri laneUri, float prio, float rate, Value body) { return new RemoteWarpDownlink(this, remoteNodeUri, nodeUri, laneUri, prio, rate, body); } RemoteWarpUplink createWarpUplink(WarpBinding link, Uri remoteNodeUri) { return new RemoteWarpUplink(this, link, remoteNodeUri); } PushRequest createPushRequest(Envelope envelope, float prio) { return new RemoteHostPushDown(this, envelope, prio); } PullRequest<Envelope> createPullEnvelope(Envelope envelope, float prio, PushRequest delegate) { return new RemoteHostPushUp(this, envelope, prio, delegate); } protected Uri resolve(Uri relativeUri) { Uri absoluteUri = this.resolveCache.get(relativeUri); if (absoluteUri == null) { absoluteUri = this.baseUri.resolve(relativeUri); if (!relativeUri.authority().isDefined()) { absoluteUri = Uri.from(relativeUri.scheme(), UriAuthority.undefined(), absoluteUri.path(), absoluteUri.query(), absoluteUri.fragment()); } absoluteUri = this.resolveCache.put(relativeUri, absoluteUri); } return absoluteUri; } @Override public HashTrieMap<Uri, NodeBinding> nodes() { return HashTrieMap.empty(); } @Override public NodeBinding getNode(Uri nodeUri) { return null; } @Override public NodeBinding openNode(Uri nodeUri) { return null; } @Override public NodeBinding openNode(Uri nodeUri, NodeBinding node) { return null; } @Override public void openUplink(LinkBinding link) { if (link instanceof WarpBinding) { openWarpUplink((WarpBinding) link); } else { UplinkError.rejectUnsupported(link); } } protected void openWarpUplink(WarpBinding link) { final Uri laneUri = link.laneUri(); final Uri remoteNodeUri = resolve(link.nodeUri()); final RemoteWarpUplink uplink = createWarpUplink(link, remoteNodeUri); link.setLinkContext(uplink); HashTrieMap<Uri, HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>>> oldUplinks; HashTrieMap<Uri, HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>>> newUplinks; do { oldUplinks = this.uplinks; HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>> nodeUplinks = oldUplinks.get(remoteNodeUri); if (nodeUplinks == null) { nodeUplinks = HashTrieMap.empty(); } HashTrieSet<RemoteWarpUplink> laneUplinks = nodeUplinks.get(laneUri); if (laneUplinks == null) { laneUplinks = HashTrieSet.empty(); } laneUplinks = laneUplinks.added(uplink); nodeUplinks = nodeUplinks.updated(laneUri, laneUplinks); newUplinks = oldUplinks.updated(remoteNodeUri, nodeUplinks); } while (!UPLINKS.compareAndSet(this, oldUplinks, newUplinks)); if (isConnected()) { uplink.didConnect(); } } void closeUplink(RemoteWarpUplink uplink) { final Uri laneUri = uplink.laneUri(); final Uri remoteNodeUri = uplink.remoteNodeUri; HashTrieMap<Uri, HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>>> oldUplinks; HashTrieMap<Uri, HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>>> newUplinks; do { oldUplinks = this.uplinks; HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>> nodeUplinks = oldUplinks.get(remoteNodeUri); if (nodeUplinks != null) { HashTrieSet<RemoteWarpUplink> laneUplinks = nodeUplinks.get(laneUri); if (laneUplinks != null) { laneUplinks = laneUplinks.removed(uplink); if (laneUplinks.isEmpty()) { nodeUplinks = nodeUplinks.removed(laneUri); if (nodeUplinks.isEmpty()) { newUplinks = oldUplinks.removed(remoteNodeUri); } else { newUplinks = oldUplinks.updated(remoteNodeUri, nodeUplinks); } } else { nodeUplinks = nodeUplinks.updated(laneUri, laneUplinks); newUplinks = oldUplinks.updated(remoteNodeUri, nodeUplinks); } } else { newUplinks = oldUplinks; break; } } else { newUplinks = oldUplinks; break; } } while (oldUplinks != newUplinks && !UPLINKS.compareAndSet(this, oldUplinks, newUplinks)); if (oldUplinks != newUplinks) { uplink.didCloseUp(); } } @Override public void pushUp(PushRequest pushRequest) { final Envelope envelope = pushRequest.envelope(); final float prio = pushRequest.prio(); final Uri remoteNodeUri = resolve(envelope.nodeUri()); final Envelope remoteEnvelope = envelope.nodeUri(remoteNodeUri); final PullRequest<Envelope> pullEnvelope = createPullEnvelope(remoteEnvelope, prio, pushRequest); this.warpSocketContext.feed(pullEnvelope); } @Override public void willConnect() { // nop } @Override public void didConnect() { final InetSocketAddress remoteAddress = this.warpSocketContext.remoteAddress(); final UriAuthority remoteAuthority = UriAuthority.from(UriHost.inetAddress(remoteAddress.getAddress()), UriPort.from(remoteAddress.getPort())); this.remoteUri = Uri.from(UriScheme.from("warp"), remoteAuthority, UriPath.slash()); REMOTE_IDENTITY.set(this, new Unauthenticated(this.requestUri, this.remoteUri, Value.absent())); connectUplinks(); this.hostContext.didConnect(); } @Override public void willSecure() { // TODO } @Override public void didSecure() { // TODO } @Override public void willBecome(IpSocket socket) { // TODO } @Override public void didBecome(IpSocket socket) { // TODO } @Override public void didUpgrade(HttpRequest<?> request, HttpResponse<?> response) { start(); } @Override public void doRead() { // nop } @Override public void didRead(Envelope envelope) { if (envelope instanceof EventMessage) { onEventMessage((EventMessage) envelope); } else if (envelope instanceof CommandMessage) { onCommandMessage((CommandMessage) envelope); } else if (envelope instanceof LinkRequest) { onLinkRequest((LinkRequest) envelope); } else if (envelope instanceof LinkedResponse) { onLinkedResponse((LinkedResponse) envelope); } else if (envelope instanceof SyncRequest) { onSyncRequest((SyncRequest) envelope); } else if (envelope instanceof SyncedResponse) { onSyncedResponse((SyncedResponse) envelope); } else if (envelope instanceof UnlinkRequest) { onUnlinkRequest((UnlinkRequest) envelope); } else if (envelope instanceof UnlinkedResponse) { onUnlinkedResponse((UnlinkedResponse) envelope); } else if (envelope instanceof AuthRequest) { onAuthRequest((AuthRequest) envelope); } else if (envelope instanceof AuthedResponse) { onAuthedResponse((AuthedResponse) envelope); } else if (envelope instanceof DeauthRequest) { onDeauthRequest((DeauthRequest) envelope); } else if (envelope instanceof DeauthedResponse) { onDeauthedResponse((DeauthedResponse) envelope); } else { onUnknownEnvelope(envelope); } } @Override public void didRead(WsControl<?, ?> frame) { final WarpSocketContext warpSocketContext = this.warpSocketContext; if (frame instanceof WsClose<?, ?>) { if (warpSocketContext != null) { warpSocketContext.write(WsClose.from(1000)); } else { close(); } } else if (frame instanceof WsPing<?, ?>) { if (warpSocketContext != null) { warpSocketContext.write(WsPong.from(frame.payload())); } } } protected void onEventMessage(EventMessage message) { final Uri nodeUri = resolve(message.nodeUri()); final Uri laneUri = message.laneUri(); final HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>> nodeUplinks = this.uplinks.get(nodeUri); if (nodeUplinks != null) { final HashTrieSet<RemoteWarpUplink> laneUplinks = nodeUplinks.get(laneUri); if (laneUplinks != null) { final EventMessage resolvedMessage = message.nodeUri(nodeUri); final Iterator<RemoteWarpUplink> uplinksIterator = laneUplinks.iterator(); while (uplinksIterator.hasNext()) { uplinksIterator.next().queueDown(resolvedMessage); } } } } protected void onCommandMessage(CommandMessage message) { final Policy policy = policy(); if (policy != null) { final PolicyDirective<CommandMessage> directive = policy.canDownlink(message, this.remoteIdentity); if (directive.isAllowed()) { final CommandMessage newMessage = directive.get(); if (newMessage != null) { message = newMessage; } } else if (directive.isDenied()) { return; } else { forbid(); return; } } final Uri nodeUri = resolve(message.nodeUri()); final Uri laneUri = message.laneUri(); final CommandMessage resolvedMessage = message.nodeUri(nodeUri); final HashTrieMap<Uri, RemoteWarpDownlink> nodeDownlinks = this.downlinks.get(nodeUri); if (nodeDownlinks != null) { final RemoteWarpDownlink laneDownlink = nodeDownlinks.get(laneUri); if (laneDownlink != null) { laneDownlink.queueUp(resolvedMessage); return; } } final PushRequest pushRequest = createPushRequest(resolvedMessage, 0.0f); this.hostContext.pushDown(pushRequest); } protected void routeDownlink(LinkAddressed envelope) { final Uri remoteNodeUri = envelope.nodeUri(); final Uri nodeUri = resolve(remoteNodeUri); final Uri laneUri = envelope.laneUri(); final float prio = envelope.prio(); final float rate = envelope.rate(); final Value body = envelope.body(); HashTrieMap<Uri, HashTrieMap<Uri, RemoteWarpDownlink>> oldDownlinks; HashTrieMap<Uri, HashTrieMap<Uri, RemoteWarpDownlink>> newDownlinks; RemoteWarpDownlink downlink = null; do { oldDownlinks = this.downlinks; HashTrieMap<Uri, RemoteWarpDownlink> nodeDownlinks = oldDownlinks.get(nodeUri); if (nodeDownlinks == null) { nodeDownlinks = HashTrieMap.empty(); } final RemoteWarpDownlink laneDownlink = nodeDownlinks.get(laneUri); if (laneDownlink != null) { if (downlink != null) { // Lost creation race. downlink.closeDown(); } downlink = laneDownlink; newDownlinks = oldDownlinks; break; } else { if (downlink == null) { downlink = createWarpDownlink(remoteNodeUri, nodeUri, laneUri, prio, rate, body); this.hostContext.openDownlink(downlink); } // TODO: don't register error links nodeDownlinks = nodeDownlinks.updated(laneUri, downlink); newDownlinks = oldDownlinks.updated(nodeUri, nodeDownlinks); } } while (oldDownlinks != newDownlinks && !DOWNLINKS.compareAndSet(this, oldDownlinks, newDownlinks)); if (oldDownlinks != newDownlinks) { downlink.openDown(); } final LinkAddressed resolvedEnvelope = envelope.nodeUri(nodeUri); downlink.queueUp(resolvedEnvelope); } protected void routeUplink(LaneAddressed envelope) { final Uri nodeUri = resolve(envelope.nodeUri()); final Uri laneUri = envelope.laneUri(); final HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>> nodeUplinks = this.uplinks.get(nodeUri); if (nodeUplinks != null) { final HashTrieSet<RemoteWarpUplink> laneUplinks = nodeUplinks.get(laneUri); if (laneUplinks != null) { final LaneAddressed resolvedEnvelope = envelope.nodeUri(nodeUri); final Iterator<RemoteWarpUplink> uplinksIterator = laneUplinks.iterator(); while (uplinksIterator.hasNext()) { uplinksIterator.next().queueDown(resolvedEnvelope); } } } } protected void onLinkRequest(LinkRequest request) { final Policy policy = policy(); if (policy != null) { final PolicyDirective<LinkRequest> directive = policy.canLink(request, this.remoteIdentity); if (directive.isAllowed()) { final LinkRequest newRequest = directive.get(); if (newRequest != null) { request = newRequest; } } else if (directive.isDenied()) { final UnlinkedResponse response = new UnlinkedResponse(request.nodeUri(), request.laneUri()); this.warpSocketContext.feed(response, 1.0f); return; } else { forbid(); return; } } routeDownlink(request); } protected void onLinkedResponse(LinkedResponse response) { routeUplink(response); } protected void onSyncRequest(SyncRequest request) { final Policy policy = policy(); if (policy != null) { final PolicyDirective<SyncRequest> directive = policy.canSync(request, this.remoteIdentity); if (directive.isAllowed()) { final SyncRequest newRequest = directive.get(); if (newRequest != null) { request = newRequest; } } else if (directive.isDenied()) { final UnlinkedResponse response = new UnlinkedResponse(request.nodeUri(), request.laneUri()); this.warpSocketContext.feed(response, 1.0f); return; } else { forbid(); return; } } routeDownlink(request); } protected void onSyncedResponse(SyncedResponse response) { routeUplink(response); } protected void onUnlinkRequest(UnlinkRequest request) { final Uri nodeUri = resolve(request.nodeUri()); final Uri laneUri = request.laneUri(); HashTrieMap<Uri, HashTrieMap<Uri, RemoteWarpDownlink>> oldDownlinks; HashTrieMap<Uri, HashTrieMap<Uri, RemoteWarpDownlink>> newDownlinks; RemoteWarpDownlink downlink; do { oldDownlinks = this.downlinks; HashTrieMap<Uri, RemoteWarpDownlink> nodeDownlinks = oldDownlinks.get(nodeUri); if (nodeDownlinks != null) { downlink = nodeDownlinks.get(laneUri); if (downlink != null) { nodeDownlinks = nodeDownlinks.removed(laneUri); if (nodeDownlinks.isEmpty()) { newDownlinks = oldDownlinks.removed(nodeUri); } else { newDownlinks = oldDownlinks.updated(nodeUri, nodeDownlinks); } } else { newDownlinks = oldDownlinks; break; } } else { newDownlinks = oldDownlinks; downlink = null; break; } } while (oldDownlinks != newDownlinks && !DOWNLINKS.compareAndSet(this, oldDownlinks, newDownlinks)); if (downlink != null) { final UnlinkRequest resolvedRequest = request.nodeUri(nodeUri); downlink.queueUp(resolvedRequest); } } protected void onUnlinkedResponse(UnlinkedResponse response) { final Uri nodeUri = resolve(response.nodeUri()); final Uri laneUri = response.laneUri(); HashTrieMap<Uri, HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>>> oldUplinks; HashTrieMap<Uri, HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>>> newUplinks; HashTrieSet<RemoteWarpUplink> laneUplinks; do { oldUplinks = this.uplinks; HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>> nodeUplinks = oldUplinks.get(nodeUri); if (nodeUplinks != null) { laneUplinks = nodeUplinks.get(laneUri); if (laneUplinks != null) { nodeUplinks = nodeUplinks.removed(laneUri); if (nodeUplinks.isEmpty()) { newUplinks = oldUplinks.removed(nodeUri); } else { newUplinks = oldUplinks.updated(nodeUri, nodeUplinks); } } else { newUplinks = oldUplinks; break; } } else { newUplinks = oldUplinks; laneUplinks = null; break; } } while (oldUplinks != newUplinks && !UPLINKS.compareAndSet(this, oldUplinks, newUplinks)); if (laneUplinks != null) { final UnlinkedResponse resolvedResponse = response.nodeUri(nodeUri); final Iterator<RemoteWarpUplink> uplinksIterator = laneUplinks.iterator(); while (uplinksIterator.hasNext()) { uplinksIterator.next().queueDown(resolvedResponse); } } } protected void onAuthRequest(AuthRequest request) { final RemoteCredentials credentials = new RemoteCredentials(this.requestUri, this.remoteUri, request.body()); final PolicyDirective<Identity> directive = this.hostContext.authenticate(credentials); if (directive != null && directive.isAllowed()) { REMOTE_IDENTITY.set(this, directive.get()); final AuthedResponse response = new AuthedResponse(); this.warpSocketContext.feed(response, 1.0f); } else { final DeauthedResponse response = new DeauthedResponse(); this.warpSocketContext.feed(response, 1.0f); } if (directive != null && directive.isForbidden()) { final WarpSocketContext warpSocketContext = this.warpSocketContext; if (warpSocketContext != null) { warpSocketContext.write(WsClose.from(1008, "Unauthorized")); } else { close(); } } } protected void onAuthedResponse(AuthedResponse response) { // TODO } protected void onDeauthRequest(DeauthRequest request) { REMOTE_IDENTITY.set(this, null); final DeauthedResponse response = new DeauthedResponse(); this.warpSocketContext.feed(response, 1.0f); } protected void onDeauthedResponse(DeauthedResponse response) { // TODO } protected void onUnknownEnvelope(Envelope envelope) { // nop } protected void forbid() { final WarpSocketContext warpSocketContext = this.warpSocketContext; if (warpSocketContext != null) { warpSocketContext.write(WsClose.from(1008, "Forbidden")); } else { close(); } } @Override public void doWrite() { // nop } @Override public void didWrite(Envelope envelope) { // nop } @Override public void didWrite(WsControl<?, ?> frame) { // nop } @Override public void didTimeout() { // TODO } @Override public void didDisconnect() { disconnectUplinks(); this.hostContext.didDisconnect(); reconnect(); } @Override public LinkBinding bindDownlink(Downlink downlink) { return this.hostContext.bindDownlink(downlink); } @Override public void openDownlink(LinkBinding link) { this.hostContext.openDownlink(link); } @Override public void closeDownlink(LinkBinding link) { this.hostContext.closeDownlink(link); } @Override public void pushDown(PushRequest pushRequest) { this.hostContext.pushDown(pushRequest); } protected void willOpen() { // nop } protected void didOpen() { // nop } protected void willLoad() { // nop } protected void didLoad() { // nop } protected void willStart() { // nop } protected void didStart() { // nop } protected void willStop() { // nop } protected void didStop() { // nop } protected void willUnload() { // nop } protected void didUnload() { // nop } protected void willClose() { try { closeDownlinks(); } finally { try { closeUplinks(); } finally { try { final HostContext hostContext = this.hostContext; if (hostContext != null) { hostContext.close(); } } finally { final WarpSocketContext warpSocketContext = this.warpSocketContext; if (warpSocketContext != null) { warpSocketContext.close(); } } } } } @Override public void didFail(Throwable error) { error.printStackTrace(); this.warpSocketContext.write(WsClose.from(1002, error.getMessage())); this.hostContext.close(); } protected void reconnect() { close(); } protected void closeDownlinks() { HashTrieMap<Uri, HashTrieMap<Uri, RemoteWarpDownlink>> oldDownlinks; final HashTrieMap<Uri, HashTrieMap<Uri, RemoteWarpDownlink>> newDownlinks = HashTrieMap.empty(); do { oldDownlinks = this.downlinks; } while (oldDownlinks != newDownlinks && !DOWNLINKS.compareAndSet(this, oldDownlinks, newDownlinks)); final Iterator<HashTrieMap<Uri, RemoteWarpDownlink>> nodeDownlinksIterator = oldDownlinks.valueIterator(); while (nodeDownlinksIterator.hasNext()) { final HashTrieMap<Uri, RemoteWarpDownlink> nodeDownlinks = nodeDownlinksIterator.next(); final Iterator<RemoteWarpDownlink> laneDownlinks = nodeDownlinks.valueIterator(); while (laneDownlinks.hasNext()) { final RemoteWarpDownlink downlink = laneDownlinks.next(); downlink.closeDown(); } } } protected void closeUplinks() { HashTrieMap<Uri, HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>>> oldUplinks; final HashTrieMap<Uri, HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>>> newUplinks = HashTrieMap.empty(); do { oldUplinks = this.uplinks; } while (oldUplinks != newUplinks && !UPLINKS.compareAndSet(this, oldUplinks, newUplinks)); final Iterator<HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>>> nodeUplinksIterator = this.uplinks.valueIterator(); while (nodeUplinksIterator.hasNext()) { final HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>> nodeUplinks = nodeUplinksIterator.next(); final Iterator<HashTrieSet<RemoteWarpUplink>> laneUplinksIterator = nodeUplinks.valueIterator(); while (laneUplinksIterator.hasNext()) { final HashTrieSet<RemoteWarpUplink> laneUplinks = laneUplinksIterator.next(); final Iterator<RemoteWarpUplink> uplinksIterator = laneUplinks.iterator(); while (uplinksIterator.hasNext()) { final RemoteWarpUplink uplink = uplinksIterator.next(); uplink.closeUp(); } } } } protected void connectUplinks() { final Iterator<HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>>> nodeUplinksIterator = this.uplinks.valueIterator(); while (nodeUplinksIterator.hasNext()) { final HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>> nodeUplinks = nodeUplinksIterator.next(); final Iterator<HashTrieSet<RemoteWarpUplink>> laneUplinksIterator = nodeUplinks.valueIterator(); while (laneUplinksIterator.hasNext()) { final HashTrieSet<RemoteWarpUplink> laneUplinks = laneUplinksIterator.next(); final Iterator<RemoteWarpUplink> uplinksIterator = laneUplinks.iterator(); while (uplinksIterator.hasNext()) { final RemoteWarpUplink uplink = uplinksIterator.next(); uplink.didConnect(); } } } } protected void disconnectUplinks() { if (isConnected()) { final Iterator<HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>>> nodeUplinksIterator = this.uplinks.valueIterator(); while (nodeUplinksIterator.hasNext()) { final HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>> nodeUplinks = nodeUplinksIterator.next(); final Iterator<HashTrieSet<RemoteWarpUplink>> laneUplinksIterator = nodeUplinks.valueIterator(); while (laneUplinksIterator.hasNext()) { final HashTrieSet<RemoteWarpUplink> laneUplinks = laneUplinksIterator.next(); final Iterator<RemoteWarpUplink> uplinksIterator = laneUplinks.iterator(); while (uplinksIterator.hasNext()) { final RemoteWarpUplink uplink = uplinksIterator.next(); uplink.didDisconnect(); } } } } } @Override public void trace(Object message) { this.hostContext.trace(message); } @Override public void debug(Object message) { this.hostContext.debug(message); } @Override public void info(Object message) { this.hostContext.info(message); } @Override public void warn(Object message) { this.hostContext.warn(message); } @Override public void error(Object message) { this.hostContext.error(message); } static final int PRIMARY = 1 << 0; static final int REPLICA = 1 << 1; static final int MASTER = 1 << 2; static final int SLAVE = 1 << 3; static final int URI_RESOLUTION_CACHE_SIZE; static final AtomicIntegerFieldUpdater<RemoteHost> FLAGS = AtomicIntegerFieldUpdater.newUpdater(RemoteHost.class, "flags"); static final AtomicReferenceFieldUpdater<RemoteHost, Identity> REMOTE_IDENTITY = AtomicReferenceFieldUpdater.newUpdater(RemoteHost.class, Identity.class, "remoteIdentity"); @SuppressWarnings("unchecked") static final AtomicReferenceFieldUpdater<RemoteHost, HashTrieMap<Uri, HashTrieMap<Uri, RemoteWarpDownlink>>> DOWNLINKS = AtomicReferenceFieldUpdater.newUpdater(RemoteHost.class, (Class<HashTrieMap<Uri, HashTrieMap<Uri, RemoteWarpDownlink>>>) (Class<?>) HashTrieMap.class, "downlinks"); @SuppressWarnings("unchecked") static final AtomicReferenceFieldUpdater<RemoteHost, HashTrieMap<Uri, HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>>>> UPLINKS = AtomicReferenceFieldUpdater.newUpdater(RemoteHost.class, (Class<HashTrieMap<Uri, HashTrieMap<Uri, HashTrieSet<RemoteWarpUplink>>>>) (Class<?>) HashTrieMap.class, "uplinks"); static { int uriResolutionCacheSize; try { uriResolutionCacheSize = Integer.parseInt(System.getProperty("swim.remote.uri.resolution.cache.size")); } catch (NumberFormatException e) { uriResolutionCacheSize = 8; } URI_RESOLUTION_CACHE_SIZE = uriResolutionCacheSize; } } final class RemoteHostPushDown implements PushRequest { final RemoteHost host; final Envelope envelope; final float prio; RemoteHostPushDown(RemoteHost host, Envelope envelope, float prio) { this.host = host; this.envelope = envelope; this.prio = prio; } @Override public Uri meshUri() { return Uri.empty(); } @Override public Uri hostUri() { return Uri.empty(); } @Override public Uri nodeUri() { return this.envelope.nodeUri(); } @Override public Identity identity() { return this.host.remoteIdentity(); } @Override public Envelope envelope() { return this.envelope; } @Override public float prio() { return this.prio; } @Override public void didDeliver() { // nop } @Override public void didDecline() { // nop } } final class RemoteHostPushUp implements PullRequest<Envelope> { final RemoteHost host; final Envelope envelope; final float prio; final PushRequest delegate; RemoteHostPushUp(RemoteHost host, Envelope envelope, float prio, PushRequest delegate) { this.host = host; this.envelope = envelope; this.prio = prio; this.delegate = delegate; } @Override public float prio() { return this.prio; } @Override public void pull(PullContext<? super Envelope> context) { context.push(this.envelope); this.delegate.didDeliver(); } }
0
java-sources/ai/swim/swim-remote/3.10.0/swim
java-sources/ai/swim/swim-remote/3.10.0/swim/remote/RemoteHostClient.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.remote; import java.net.InetSocketAddress; import swim.collections.FingerTrieSeq; import swim.concurrent.Conts; import swim.concurrent.TimerFunction; import swim.concurrent.TimerRef; import swim.http.HttpRequest; import swim.http.HttpResponse; import swim.io.IpInterface; import swim.io.IpSocketModem; import swim.io.IpSocketRef; import swim.io.http.HttpClient; import swim.io.http.HttpClientContext; import swim.io.http.HttpClientModem; import swim.io.http.HttpSettings; import swim.io.warp.AbstractWarpClient; import swim.io.warp.WarpSettings; import swim.io.warp.WarpWebSocket; import swim.runtime.HostContext; import swim.uri.Uri; import swim.uri.UriAuthority; import swim.uri.UriPath; import swim.uri.UriScheme; import swim.ws.WsRequest; public class RemoteHostClient extends RemoteHost { final IpInterface endpoint; final WarpSettings warpSettings; HttpClient client; TimerRef reconnectTimer; double reconnectTimeout; public RemoteHostClient(Uri baseUri, IpInterface endpoint, WarpSettings warpSettings) { super(Uri.empty(), baseUri); this.endpoint = endpoint; this.warpSettings = warpSettings; } public RemoteHostClient(Uri baseUri, IpInterface endpoint) { this(baseUri, endpoint, WarpSettings.standard()); } @Override public void setHostContext(HostContext hostContext) { super.setHostContext(hostContext); } public void connect() { final String scheme = this.baseUri.schemeName(); final boolean isSecure = "warps".equals(scheme) || "swims".equals(scheme); final UriAuthority remoteAuthority = this.baseUri.authority(); final String remoteAddress = remoteAuthority.host().address(); final int remotePort = remoteAuthority.port().number(); final int requestPort = remotePort > 0 ? remotePort : isSecure ? 443 : 80; if (this.client == null) { final Uri requestUri = Uri.from(UriScheme.from("http"), remoteAuthority, UriPath.slash(), this.baseUri.query()); final WsRequest wsRequest = WsRequest.from(requestUri, PROTOCOL_LIST); final WarpWebSocket webSocket = new WarpWebSocket(this, this.warpSettings); this.client = new RemoteHostClientBinding(this, webSocket, wsRequest, this.warpSettings); setWarpSocketContext(webSocket); // eagerly set } if (isSecure) { connectHttps(new InetSocketAddress(remoteAddress, requestPort), this.client, this.warpSettings.httpSettings()); } else { connectHttp(new InetSocketAddress(remoteAddress, requestPort), this.client, this.warpSettings.httpSettings()); } } protected IpSocketRef connectHttp(InetSocketAddress remoteAddress, HttpClient client, HttpSettings httpSettings) { final HttpClientModem modem = new HttpClientModem(client, httpSettings); final IpSocketModem<HttpResponse<?>, HttpRequest<?>> socket = new IpSocketModem<HttpResponse<?>, HttpRequest<?>>(modem); return this.endpoint.connectTcp(remoteAddress, socket, httpSettings.ipSettings()); } protected IpSocketRef connectHttps(InetSocketAddress remoteAddress, HttpClient client, HttpSettings httpSettings) { final HttpClientModem modem = new HttpClientModem(client, httpSettings); final IpSocketModem<HttpResponse<?>, HttpRequest<?>> socket = new IpSocketModem<HttpResponse<?>, HttpRequest<?>>(modem); return this.endpoint.connectTls(remoteAddress, socket, httpSettings.ipSettings()); } @Override protected void reconnect() { //if (this.uplinks.isEmpty()) { // close(); //} if (this.reconnectTimer != null && this.reconnectTimer.isScheduled()) { return; } if (this.reconnectTimeout == 0.0) { final double jitter = 1000.0 * Math.random(); this.reconnectTimeout = 500.0 + jitter; } else { this.reconnectTimeout = Math.min(1.8 * this.reconnectTimeout, MAX_RECONNECT_TIMEOUT); } this.reconnectTimer = this.hostContext.schedule().setTimer((long) this.reconnectTimeout, new RemoteHostClientReconnectTimer(this)); } @Override public void didConnect() { if (this.reconnectTimer != null) { this.reconnectTimer.cancel(); this.reconnectTimer = null; } this.reconnectTimeout = 0.0; super.didConnect(); } @Override protected void willOpen() { connect(); super.willOpen(); } static final double MAX_RECONNECT_TIMEOUT = 15000.0; static final FingerTrieSeq<String> PROTOCOL_LIST = FingerTrieSeq.of("warp0", "swim-0.0"); } final class RemoteHostClientBinding extends AbstractWarpClient { final RemoteHostClient client; final WarpWebSocket webSocket; final WsRequest wsRequest; final WarpSettings warpSettings; RemoteHostClientBinding(RemoteHostClient client, WarpWebSocket webSocket, WsRequest wsRequest, WarpSettings warpSettings) { super(warpSettings); this.client = client; this.webSocket = webSocket; this.wsRequest = wsRequest; this.warpSettings = warpSettings; } @Override public void setHttpClientContext(HttpClientContext context) { super.setHttpClientContext(context); } @Override public void didConnect() { super.didConnect(); doRequest(upgrade(this.webSocket, this.wsRequest)); } @Override public void didDisconnect() { webSocket.close(); this.client.didDisconnect(); } } final class RemoteHostClientReconnectTimer implements TimerFunction { final RemoteHostClient client; RemoteHostClientReconnectTimer(RemoteHostClient client) { this.client = client; } @Override public void runTimer() { try { this.client.connect(); } catch (Throwable error) { if (Conts.isNonFatal(error)) { this.client.reconnect(); // schedule reconnect } else { throw error; } } } }
0
java-sources/ai/swim/swim-remote/3.10.0/swim
java-sources/ai/swim/swim-remote/3.10.0/swim/remote/RemoteHostException.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.remote; public class RemoteHostException extends RuntimeException { private static final long serialVersionUID = 1L; public RemoteHostException(String message, Throwable cause) { super(message, cause); } public RemoteHostException(String message) { super(message); } public RemoteHostException(Throwable cause) { super(cause); } }
0
java-sources/ai/swim/swim-remote/3.10.0/swim
java-sources/ai/swim/swim-remote/3.10.0/swim/remote/RemoteKernel.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.remote; import swim.io.IpInterface; import swim.io.http.HttpSettings; import swim.io.warp.WarpSettings; import swim.io.ws.WsSettings; import swim.kernel.KernelProxy; import swim.runtime.HostBinding; import swim.runtime.HostDef; import swim.structure.Value; import swim.uri.Uri; public class RemoteKernel extends KernelProxy { final double kernelPriority; WarpSettings warpSettings; public RemoteKernel(double kernelPriority) { this.kernelPriority = kernelPriority; } public RemoteKernel() { this(KERNEL_PRIORITY); } @Override public final double kernelPriority() { return this.kernelPriority; } public HttpSettings httpSettings() { return HttpSettings.from(ipSettings()); } public WsSettings wsSettings() { return WsSettings.from(httpSettings()); } public final WarpSettings warpSettings() { if (this.warpSettings == null) { this.warpSettings = WarpSettings.from(wsSettings()); // TODO: use moduleConfig } return this.warpSettings; } @Override public HostBinding createHost(String edgeName, Uri meshUri, Value partKey, Uri hostUri) { if (hostUri.host().isDefined() && !"swim".equals(partKey.stringValue(null))) { final IpInterface endpoint = kernelWrapper().unwrapKernel(IpInterface.class); return new RemoteHostClient(hostUri, endpoint, warpSettings()); } return super.createHost(edgeName, meshUri, partKey, hostUri); } @Override public HostBinding createHost(String edgeName, Uri meshUri, Value partKey, HostDef hostDef) { final Uri hostUri = hostDef.hostUri(); if (hostUri != null && hostUri.host().isDefined() && !"swim".equals(partKey.stringValue(null))) { final IpInterface endpoint = kernelWrapper().unwrapKernel(IpInterface.class); return new RemoteHostClient(hostUri, endpoint, warpSettings()); } return super.createHost(edgeName, meshUri, partKey, hostUri); } private static final double KERNEL_PRIORITY = 0.25; public static RemoteKernel fromValue(Value moduleConfig) { final Value header = moduleConfig.getAttr("kernel"); final String kernelClassName = header.get("class").stringValue(null); if (kernelClassName == null || RemoteKernel.class.getName().equals(kernelClassName)) { final double kernelPriority = header.get("priority").doubleValue(KERNEL_PRIORITY); return new RemoteKernel(kernelPriority); } return null; } }
0
java-sources/ai/swim/swim-remote/3.10.0/swim
java-sources/ai/swim/swim-remote/3.10.0/swim/remote/RemoteWarpDownlink.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.remote; import java.net.InetSocketAddress; import java.security.Principal; import java.security.cert.Certificate; import java.util.Collection; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import swim.api.auth.Identity; import swim.concurrent.PullContext; import swim.concurrent.PullRequest; import swim.runtime.CellContext; import swim.runtime.LinkContext; import swim.runtime.WarpBinding; import swim.runtime.WarpContext; import swim.structure.Value; import swim.uri.Uri; import swim.warp.Envelope; import swim.warp.LinkRequest; import swim.warp.SyncRequest; class RemoteWarpDownlink implements WarpBinding, PullRequest<Envelope> { final RemoteHost host; final Uri remoteNodeUri; final Uri nodeUri; final Uri laneUri; final float prio; final float rate; final Value body; final ConcurrentLinkedQueue<Envelope> upQueue; WarpContext linkContext; PullContext<? super Envelope> pullContext; volatile int status; RemoteWarpDownlink(RemoteHost host, Uri remoteNodeUri, Uri nodeUri, Uri laneUri, float prio, float rate, Value body) { this.host = host; this.remoteNodeUri = remoteNodeUri; this.nodeUri = nodeUri; this.laneUri = laneUri; this.prio = prio; this.rate = rate; this.body = body; this.upQueue = new ConcurrentLinkedQueue<Envelope>(); } @Override public final WarpBinding linkWrapper() { return this; } @Override public final WarpContext linkContext() { return this.linkContext; } @Override public void setLinkContext(LinkContext linkContext) { this.linkContext = (WarpContext) linkContext; } @Override public CellContext cellContext() { return null; } @Override public void setCellContext(CellContext cellContext) { // nop } @SuppressWarnings("unchecked") @Override public <T> T unwrapLink(Class<T> linkClass) { if (linkClass.isAssignableFrom(getClass())) { return (T) this; } else if (this.linkContext != null) { return this.linkContext.unwrapLink(linkClass); } else { return null; } } @Override public final Uri meshUri() { return Uri.empty(); } @Override public final Uri hostUri() { return Uri.empty(); } @Override public final Uri nodeUri() { return this.nodeUri; } @Override public final Uri laneUri() { return this.laneUri; } @Override public final float prio() { return this.prio; } @Override public final float rate() { return this.rate; } @Override public final Value body() { return this.body; } @Override public Value linkKey() { return this.linkContext.linkKey(); } @Override public boolean keepLinked() { return false; } @Override public boolean keepSynced() { return false; } @Override public boolean isConnectedDown() { return this.host.isConnected(); } @Override public boolean isRemoteDown() { return this.host.isRemote(); } @Override public boolean isSecureDown() { return this.host.isSecure(); } @Override public String securityProtocolDown() { return this.host.securityProtocol(); } @Override public String cipherSuiteDown() { return this.host.cipherSuite(); } @Override public InetSocketAddress localAddressDown() { return this.host.localAddress(); } @Override public Identity localIdentityDown() { return this.host.localIdentity(); } @Override public Principal localPrincipalDown() { return this.host.localPrincipal(); } @Override public Collection<Certificate> localCertificatesDown() { return this.host.localCertificates(); } @Override public InetSocketAddress remoteAddressDown() { return this.host.remoteAddress(); } @Override public Identity remoteIdentityDown() { return this.host.remoteIdentity(); } @Override public Principal remotePrincipalDown() { return this.host.remotePrincipal(); } @Override public Collection<Certificate> remoteCertificatesDown() { return this.host.remoteCertificates(); } @Override public void feedDown() { int oldStatus; int newStatus; do { oldStatus = this.status; if ((oldStatus & PULLING_DOWN) == 0) { newStatus = oldStatus & ~FEEDING_DOWN | PULLING_DOWN; } else { newStatus = oldStatus | FEEDING_DOWN; } } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if ((oldStatus & PULLING_DOWN) == 0) { this.host.warpSocketContext.feed(this); } } @Override public void pull(PullContext<? super Envelope> pullContext) { this.pullContext = pullContext; this.linkContext.pullDown(); } @Override public void pushDown(Envelope envelope) { int oldStatus; int newStatus; do { oldStatus = this.status; newStatus = oldStatus & ~PULLING_DOWN; } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if (oldStatus != newStatus) { final Envelope remoteEnvelope = envelope.nodeUri(this.remoteNodeUri); this.pullContext.push(remoteEnvelope); this.pullContext = null; } } @Override public void skipDown() { int oldStatus; int newStatus; do { oldStatus = this.status; newStatus = oldStatus & ~PULLING_DOWN; } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if (oldStatus != newStatus) { this.pullContext.skip(); this.pullContext = null; } } public void queueUp(Envelope envelope) { this.upQueue.add(envelope); int oldStatus; int newStatus; do { oldStatus = this.status; newStatus = oldStatus | FEEDING_UP; if (envelope instanceof SyncRequest) { newStatus |= SYNC; } } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if ((oldStatus & FEEDING_UP) != (newStatus & FEEDING_UP)) { this.linkContext.feedUp(); } } @Override public void pullUp() { final Envelope envelope = this.upQueue.poll(); int oldStatus; int newStatus; do { oldStatus = this.status; newStatus = oldStatus & ~FEEDING_UP; } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if (envelope != null) { this.linkContext.pushUp(envelope); } feedUpQueue(); } void feedUpQueue() { int oldStatus; int newStatus; do { oldStatus = this.status; if (!this.upQueue.isEmpty()) { newStatus = oldStatus | FEEDING_UP; } else { newStatus = oldStatus; } } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if (oldStatus != newStatus) { this.linkContext.feedUp(); } } @Override public void reopen() { this.linkContext.closeUp(); int oldStatus; int newStatus; do { oldStatus = this.status; newStatus = oldStatus & ~FEEDING_UP; } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); this.host.hostContext.openDownlink(this); this.linkContext.didOpenDown(); final Envelope request; if ((oldStatus & SYNC) != 0) { request = new SyncRequest(this.nodeUri, this.laneUri, this.prio, this.rate, this.body); } else { request = new LinkRequest(this.nodeUri, this.laneUri, this.prio, this.rate, this.body); } queueUp(request); } @Override public void openDown() { this.linkContext.didOpenDown(); } @Override public void closeDown() { this.linkContext.didCloseDown(); } @Override public void didConnect() { // nop } @Override public void didDisconnect() { // nop } @Override public void didCloseUp() { // nop } @Override public void didFail(Throwable error) { error.printStackTrace(); } @Override public void traceDown(Object message) { this.host.trace(message); } @Override public void debugDown(Object message) { this.host.debug(message); } @Override public void infoDown(Object message) { this.host.info(message); } @Override public void warnDown(Object message) { this.host.warn(message); } @Override public void errorDown(Object message) { this.host.error(message); } static final int FEEDING_DOWN = 1 << 0; static final int PULLING_DOWN = 1 << 1; static final int FEEDING_UP = 1 << 2; static final int SYNC = 1 << 3; static final AtomicIntegerFieldUpdater<RemoteWarpDownlink> STATUS = AtomicIntegerFieldUpdater.newUpdater(RemoteWarpDownlink.class, "status"); }
0
java-sources/ai/swim/swim-remote/3.10.0/swim
java-sources/ai/swim/swim-remote/3.10.0/swim/remote/RemoteWarpUplink.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.remote; import java.net.InetSocketAddress; import java.security.Principal; import java.security.cert.Certificate; import java.util.Collection; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import swim.api.auth.Identity; import swim.concurrent.PullContext; import swim.concurrent.PullRequest; import swim.runtime.LinkKeys; import swim.runtime.WarpBinding; import swim.runtime.WarpContext; import swim.structure.Value; import swim.uri.Uri; import swim.warp.Envelope; class RemoteWarpUplink implements WarpContext, PullRequest<Envelope> { final RemoteHost host; final WarpBinding link; final Uri remoteNodeUri; final Value linkKey; final ConcurrentLinkedQueue<Envelope> downQueue; PullContext<? super Envelope> pullContext; volatile int status; RemoteWarpUplink(RemoteHost host, WarpBinding link, Uri remoteNodeUri, Value linkKey) { this.host = host; this.link = link; this.remoteNodeUri = remoteNodeUri; this.linkKey = linkKey.commit(); this.downQueue = new ConcurrentLinkedQueue<Envelope>(); } RemoteWarpUplink(RemoteHost host, WarpBinding link, Uri remoteNodeUri) { this(host, link, remoteNodeUri, LinkKeys.generateLinkKey()); } @Override public final WarpBinding linkWrapper() { return this.link.linkWrapper(); } public final WarpBinding linkBinding() { return this.link; } @SuppressWarnings("unchecked") @Override public <T> T unwrapLink(Class<T> linkClass) { if (linkClass.isAssignableFrom(getClass())) { return (T) this; } else { return null; } } public final Uri nodeUri() { return this.link.nodeUri(); } public final Uri laneUri() { return this.link.laneUri(); } public final Value linkKey() { return this.linkKey; } public final float prio() { return this.link.prio(); } @Override public boolean isConnectedUp() { return this.host.isConnected(); } @Override public boolean isRemoteUp() { return this.host.isRemote(); } @Override public boolean isSecureUp() { return this.host.isSecure(); } @Override public String securityProtocolUp() { return this.host.securityProtocol(); } @Override public String cipherSuiteUp() { return this.host.cipherSuite(); } @Override public InetSocketAddress localAddressUp() { return this.host.localAddress(); } @Override public Identity localIdentityUp() { return this.host.localIdentity(); } @Override public Principal localPrincipalUp() { return this.host.localPrincipal(); } @Override public Collection<Certificate> localCertificatesUp() { return this.host.localCertificates(); } @Override public InetSocketAddress remoteAddressUp() { return this.host.remoteAddress(); } @Override public Identity remoteIdentityUp() { return this.host.remoteIdentity(); } @Override public Principal remotePrincipalUp() { return this.host.remotePrincipal(); } @Override public Collection<Certificate> remoteCertificatesUp() { return this.host.remoteCertificates(); } public void queueDown(Envelope envelope) { this.downQueue.add(envelope); int oldStatus; int newStatus; do { oldStatus = this.status; newStatus = oldStatus | FEEDING_DOWN; } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if (oldStatus != newStatus) { this.link.feedDown(); } } @Override public void pullDown() { final Envelope envelope = this.downQueue.poll(); int oldStatus; int newStatus; do { oldStatus = this.status; newStatus = oldStatus & ~FEEDING_DOWN; } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if (envelope != null) { this.link.pushDown(envelope); } feedDownQueue(); } void feedDownQueue() { int oldStatus; int newStatus; do { oldStatus = this.status; if (!this.downQueue.isEmpty()) { newStatus = oldStatus | FEEDING_DOWN; } else { newStatus = oldStatus; } } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if (oldStatus != newStatus) { this.link.feedDown(); } } @Override public void feedUp() { int oldStatus; int newStatus; do { oldStatus = this.status; if ((oldStatus & PULLING_UP) == 0) { newStatus = oldStatus & ~FEEDING_UP | PULLING_UP; } else { newStatus = oldStatus | FEEDING_UP; } } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if ((oldStatus & PULLING_UP) == 0) { this.host.warpSocketContext.feed(this); } } @Override public void pull(PullContext<? super Envelope> pullContext) { this.pullContext = pullContext; this.link.pullUp(); } @Override public void pushUp(Envelope envelope) { int oldStatus; int newStatus; do { oldStatus = this.status; newStatus = oldStatus & ~PULLING_UP; } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if (oldStatus != newStatus && this.pullContext != null) { final Envelope remoteEnvelope = envelope.nodeUri(this.remoteNodeUri); this.pullContext.push(remoteEnvelope); this.pullContext = null; } } @Override public void skipUp() { int oldStatus; int newStatus; do { oldStatus = this.status; newStatus = oldStatus & ~PULLING_UP; } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if (oldStatus != newStatus && this.pullContext != null) { this.pullContext.skip(); this.pullContext = null; } } @Override public void closeUp() { this.host.closeUplink(this); } @Override public void didOpenDown() { // nop } public void didConnect() { this.link.didConnect(); } public void didDisconnect() { this.link.didDisconnect(); STATUS.set(this, 0); } @Override public void didCloseDown() { // nop } public void didCloseUp() { this.link.didCloseUp(); } @Override public void traceUp(Object message) { this.host.trace(message); } @Override public void debugUp(Object message) { this.host.debug(message); } @Override public void infoUp(Object message) { this.host.info(message); } @Override public void warnUp(Object message) { this.host.warn(message); } @Override public void errorUp(Object message) { this.host.error(message); } static final int FEEDING_DOWN = 1 << 0; static final int FEEDING_UP = 1 << 1; static final int PULLING_UP = 1 << 2; static final AtomicIntegerFieldUpdater<RemoteWarpUplink> STATUS = AtomicIntegerFieldUpdater.newUpdater(RemoteWarpUplink.class, "status"); }
0
java-sources/ai/swim/swim-remote/3.10.0/swim
java-sources/ai/swim/swim-remote/3.10.0/swim/remote/Unauthenticated.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.remote; import swim.api.auth.Identity; import swim.api.store.Store; import swim.structure.Value; import swim.uri.Uri; public class Unauthenticated implements Identity { final Uri requestUri; final Uri fromUri; final Value subject; public Unauthenticated(Uri requestUri, Uri fromUri, Value subject) { this.requestUri = requestUri; this.fromUri = fromUri; this.subject = subject; } @Override public boolean isAuthenticated() { return false; } @Override public Uri requestUri() { return this.requestUri; } @Override public Uri fromUri() { return this.fromUri; } @Override public Value subject() { return this.subject; } @Override public Store data() { throw new UnsupportedOperationException(); // TODO } @Override public Store session() { throw new UnsupportedOperationException(); // TODO } }
0
java-sources/ai/swim/swim-remote/3.10.0/swim
java-sources/ai/swim/swim-remote/3.10.0/swim/remote/package-info.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /** * Web Agent remote router. */ package swim.remote;
0
java-sources/ai/swim/swim-runtime
java-sources/ai/swim/swim-runtime/3.10.0/module-info.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /** * Swim runtime interfaces. */ module swim.runtime { requires swim.util; requires transitive swim.codec; requires transitive swim.structure; requires transitive swim.math; requires transitive swim.spatial; requires transitive swim.http; requires transitive swim.mqtt; requires transitive swim.warp; requires transitive swim.concurrent; requires transitive swim.api; requires transitive swim.store; exports swim.runtime; exports swim.runtime.agent; exports swim.runtime.downlink; exports swim.runtime.http; exports swim.runtime.lane; exports swim.runtime.router; exports swim.runtime.scope; }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/AbstractDownlinkBinding.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import java.net.InetSocketAddress; import java.security.Principal; import java.security.cert.Certificate; import java.util.Collection; import swim.api.auth.Identity; import swim.collections.FingerTrieSeq; import swim.structure.Value; import swim.uri.Uri; import swim.util.Log; public abstract class AbstractDownlinkBinding implements LinkBinding, Log { protected final Uri meshUri; protected final Uri hostUri; protected final Uri nodeUri; protected final Uri laneUri; public AbstractDownlinkBinding(Uri meshUri, Uri hostUri, Uri nodeUri, Uri laneUri) { this.meshUri = meshUri; this.hostUri = hostUri; this.nodeUri = nodeUri; this.laneUri = laneUri; } @Override public abstract LinkBinding linkWrapper(); @Override public abstract LinkContext linkContext(); @Override public abstract CellContext cellContext(); @SuppressWarnings("unchecked") @Override public <T> T unwrapLink(Class<T> linkClass) { if (linkClass.isAssignableFrom(getClass())) { return (T) this; } else { return linkContext().unwrapLink(linkClass); } } @Override public final Uri meshUri() { return this.meshUri; } @Override public final Uri hostUri() { return this.hostUri; } @Override public final Uri nodeUri() { return this.nodeUri; } @Override public final Uri laneUri() { return this.laneUri; } @Override public final Value linkKey() { return linkContext().linkKey(); } @Override public boolean isConnectedDown() { return true; } @Override public boolean isRemoteDown() { return false; } @Override public boolean isSecureDown() { return true; } @Override public String securityProtocolDown() { return null; } @Override public String cipherSuiteDown() { return null; } @Override public InetSocketAddress localAddressDown() { return null; } @Override public final Identity localIdentityDown() { return null; } @Override public Principal localPrincipalDown() { return null; } public Collection<Certificate> localCertificatesDown() { return FingerTrieSeq.empty(); } @Override public InetSocketAddress remoteAddressDown() { return null; } @Override public final Identity remoteIdentityDown() { return null; } @Override public Principal remotePrincipalDown() { return null; } public Collection<Certificate> remoteCertificatesDown() { return FingerTrieSeq.empty(); } public boolean isConnected() { return linkContext().isConnectedUp(); } public boolean isRemote() { return linkContext().isRemoteUp(); } public boolean isSecure() { return linkContext().isSecureUp(); } public String securityProtocol() { return linkContext().securityProtocolUp(); } public String cipherSuite() { return linkContext().cipherSuiteUp(); } public InetSocketAddress localAddress() { return linkContext().localAddressUp(); } public Identity localIdentity() { return linkContext().localIdentityUp(); } public Principal localPrincipal() { return linkContext().localPrincipalUp(); } public Collection<Certificate> localCertificates() { return linkContext().localCertificatesUp(); } public InetSocketAddress remoteAddress() { return linkContext().remoteAddressUp(); } public Identity remoteIdentity() { return linkContext().remoteIdentityUp(); } public Principal remotePrincipal() { return linkContext().remotePrincipalUp(); } public Collection<Certificate> remoteCertificates() { return linkContext().remoteCertificatesUp(); } @Override public abstract void reopen(); @Override public abstract void openDown(); @Override public abstract void closeDown(); @Override public abstract void didConnect(); @Override public abstract void didDisconnect(); @Override public abstract void didCloseUp(); @Override public abstract void didFail(Throwable error); @Override public void traceDown(Object message) { // nop } @Override public void debugDown(Object message) { // nop } @Override public void infoDown(Object message) { // nop } @Override public void warnDown(Object message) { // nop } @Override public void errorDown(Object message) { // nop } @Override public void trace(Object message) { linkContext().traceUp(message); } @Override public void debug(Object message) { linkContext().debugUp(message); } @Override public void info(Object message) { linkContext().infoUp(message); } @Override public void warn(Object message) { linkContext().warnUp(message); } @Override public void error(Object message) { linkContext().errorUp(message); } }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/AbstractSwimRef.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.api.auth.Identity; import swim.api.downlink.EventDownlink; import swim.api.downlink.ListDownlink; import swim.api.downlink.MapDownlink; import swim.api.downlink.ValueDownlink; import swim.api.http.HttpDownlink; import swim.api.ref.HostRef; import swim.api.ref.LaneRef; import swim.api.ref.NodeRef; import swim.api.ref.SwimRef; import swim.api.ws.WsDownlink; import swim.runtime.downlink.EventDownlinkView; import swim.runtime.downlink.ListDownlinkView; import swim.runtime.downlink.MapDownlinkView; import swim.runtime.downlink.ValueDownlinkView; import swim.runtime.scope.HostScope; import swim.runtime.scope.LaneScope; import swim.runtime.scope.NodeScope; import swim.runtime.scope.ScopePushRequest; import swim.structure.Form; import swim.structure.Value; import swim.uri.Uri; import swim.uri.UriAuthority; import swim.warp.CommandMessage; public abstract class AbstractSwimRef implements SwimRef, CellContext { @Override public HostRef hostRef(Uri hostUri) { return new HostScope(this, stage(), meshUri(), hostUri); } @Override public HostRef hostRef(String hostUri) { return hostRef(Uri.parse(hostUri)); } @Override public NodeRef nodeRef(Uri hostUri, Uri nodeUri) { if (nodeUri.authority().isDefined()) { nodeUri = Uri.from(nodeUri.path(), nodeUri.query(), nodeUri.fragment()); } return new NodeScope(this, stage(), meshUri(), hostUri, nodeUri); } @Override public NodeRef nodeRef(String hostUri, String nodeUri) { return nodeRef(Uri.parse(hostUri), Uri.parse(nodeUri)); } @Override public NodeRef nodeRef(Uri nodeUri) { final Uri hostUri; if (nodeUri.authority().isDefined()) { hostUri = Uri.from(nodeUri.scheme(), nodeUri.authority()); nodeUri = Uri.from(nodeUri.path(), nodeUri.query(), nodeUri.fragment()); } else { hostUri = Uri.empty(); nodeUri = Uri.from(nodeUri.scheme(), UriAuthority.undefined(), nodeUri.path(), nodeUri.query(), nodeUri.fragment()); } return new NodeScope(this, stage(), meshUri(), hostUri, nodeUri); } @Override public NodeRef nodeRef(String nodeUri) { return nodeRef(Uri.parse(nodeUri)); } @Override public LaneRef laneRef(Uri hostUri, Uri nodeUri, Uri laneUri) { if (nodeUri.authority().isDefined()) { nodeUri = Uri.from(nodeUri.path(), nodeUri.query(), nodeUri.fragment()); } return new LaneScope(this, stage(), meshUri(), hostUri, nodeUri, laneUri); } @Override public LaneRef laneRef(String hostUri, String nodeUri, String laneUri) { return laneRef(Uri.parse(hostUri), Uri.parse(nodeUri), Uri.parse(laneUri)); } @Override public LaneRef laneRef(Uri nodeUri, Uri laneUri) { final Uri hostUri; if (nodeUri.authority().isDefined()) { hostUri = Uri.from(nodeUri.scheme(), nodeUri.authority()); nodeUri = Uri.from(nodeUri.path(), nodeUri.query(), nodeUri.fragment()); } else { hostUri = Uri.empty(); nodeUri = Uri.from(nodeUri.scheme(), UriAuthority.undefined(), nodeUri.path(), nodeUri.query(), nodeUri.fragment()); } return new LaneScope(this, stage(), meshUri(), hostUri, nodeUri, laneUri); } @Override public LaneRef laneRef(String nodeUri, String laneUri) { return laneRef(Uri.parse(nodeUri), Uri.parse(laneUri)); } @Override public EventDownlink<Value> downlink() { return new EventDownlinkView<>(this, stage(), meshUri(), Uri.empty(), Uri.empty(), Uri.empty(), 0.0f, 0.0f, Value.absent(), Form.forValue()); } @Override public ListDownlink<Value> downlinkList() { return new ListDownlinkView<>(this, stage(), meshUri(), Uri.empty(), Uri.empty(), Uri.empty(), 0.0f, 0.0f, Value.absent(), Form.forValue()); } @Override public MapDownlink<Value, Value> downlinkMap() { return new MapDownlinkView<>(this, stage(), meshUri(), Uri.empty(), Uri.empty(), Uri.empty(), 0.0f, 0.0f, Value.absent(), Form.forValue(), Form.forValue()); } @Override public ValueDownlink<Value> downlinkValue() { return new ValueDownlinkView<>(this, stage(), meshUri(), Uri.empty(), Uri.empty(), Uri.empty(), 0.0f, 0.0f, Value.absent(), Form.forValue()); } @Override public <V> HttpDownlink<V> downlinkHttp() { return null; // TODO } @Override public <I, O> WsDownlink<I, O> downlinkWs() { return null; // TODO } @Override public void command(Uri hostUri, Uri nodeUri, Uri laneUri, float prio, Value body) { if (nodeUri.authority().isDefined()) { nodeUri = Uri.from(nodeUri.path(), nodeUri.query(), nodeUri.fragment()); } final Identity identity = null; final CommandMessage message = new CommandMessage(nodeUri, laneUri, body); pushDown(new ScopePushRequest(meshUri(), hostUri, identity, message, prio)); } @Override public void command(String hostUri, String nodeUri, String laneUri, float prio, Value body) { command(Uri.parse(hostUri), Uri.parse(nodeUri), Uri.parse(laneUri), prio, body); } @Override public void command(Uri hostUri, Uri nodeUri, Uri laneUri, Value body) { command(hostUri, nodeUri, laneUri, 0.0f, body); } @Override public void command(String hostUri, String nodeUri, String laneUri, Value body) { command(Uri.parse(hostUri), Uri.parse(nodeUri), Uri.parse(laneUri), body); } @Override public void command(Uri nodeUri, Uri laneUri, float prio, Value body) { final Uri hostUri; if (nodeUri.authority().isDefined()) { hostUri = Uri.from(nodeUri.scheme(), nodeUri.authority()); nodeUri = Uri.from(nodeUri.path(), nodeUri.query(), nodeUri.fragment()); } else { hostUri = Uri.empty(); nodeUri = Uri.from(nodeUri.scheme(), UriAuthority.undefined(), nodeUri.path(), nodeUri.query(), nodeUri.fragment()); } final Identity identity = null; final CommandMessage message = new CommandMessage(nodeUri, laneUri, body); pushDown(new ScopePushRequest(meshUri(), hostUri, identity, message, prio)); } @Override public void command(String nodeUri, String laneUri, float prio, Value body) { command(Uri.parse(nodeUri), Uri.parse(laneUri), prio, body); } @Override public void command(Uri nodeUri, Uri laneUri, Value body) { command(nodeUri, laneUri, 0.0f, body); } @Override public void command(String nodeUri, String laneUri, Value body) { command(Uri.parse(nodeUri), Uri.parse(laneUri), body); } @Override public abstract void close(); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/AbstractTierBinding.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; public abstract class AbstractTierBinding extends AbstractSwimRef implements TierBinding { protected volatile int status; @Override public abstract TierContext tierContext(); @Override public boolean isClosed() { final int phase = (this.status & PHASE_MASK) >>> PHASE_SHIFT; return phase == CLOSED_PHASE; } @Override public boolean isOpened() { final int phase = (this.status & PHASE_MASK) >>> PHASE_SHIFT; return phase >= OPENED_PHASE; } @Override public boolean isLoaded() { final int phase = (this.status & PHASE_MASK) >>> PHASE_SHIFT; return phase >= LOADED_PHASE; } @Override public boolean isStarted() { final int phase = (this.status & PHASE_MASK) >>> PHASE_SHIFT; return phase == STARTED_PHASE; } protected void activate(TierBinding childTier) { final int state = this.status & STATE_MASK; if (state >= STARTING_STATE) { childTier.start(); } else if (state >= LOADING_STATE) { childTier.load(); } else if (state >= OPENING_STATE) { childTier.open(); } } @Override public void open() { int oldStatus; int newStatus; int oldState; int newState; int oldPhase; final int newPhase = OPENED_PHASE; do { oldStatus = this.status; oldState = oldStatus & STATE_MASK; oldPhase = (oldStatus & PHASE_MASK) >>> PHASE_SHIFT; if (newPhase > oldPhase) { if (oldState == CLOSED_STATE) { newState = OPENING_STATE; } else { newState = oldState; } newStatus = newState & STATE_MASK | (newPhase << PHASE_SHIFT) & PHASE_MASK; } else { newState = oldState; newStatus = oldStatus; break; } } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if (oldState != newState) { if (newState == OPENING_STATE) { willOpen(); convergeState(); } } } @Override public void load() { int oldStatus; int newStatus; int oldState; int newState; int oldPhase; final int newPhase = LOADED_PHASE; do { oldStatus = this.status; oldState = oldStatus & STATE_MASK; oldPhase = (oldStatus & PHASE_MASK) >>> PHASE_SHIFT; if (newPhase > oldPhase) { if (oldState == OPENED_STATE) { newState = LOADING_STATE; } else if (oldState == CLOSED_STATE) { newState = OPENING_STATE; } else { newState = oldState; } newStatus = newState & STATE_MASK | (newPhase << PHASE_SHIFT) & PHASE_MASK; } else { newState = oldState; newStatus = oldStatus; break; } } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if (oldState != newState) { if (newState == LOADING_STATE) { willLoad(); convergeState(); } else if (newState == OPENING_STATE) { willOpen(); convergeState(); } } } @Override public void start() { int oldStatus; int newStatus; int oldState; int newState; int oldPhase; final int newPhase = STARTED_PHASE; do { oldStatus = this.status; oldState = oldStatus & STATE_MASK; oldPhase = (oldStatus & PHASE_MASK) >>> PHASE_SHIFT; if (newPhase > oldPhase) { if (oldState == LOADED_STATE) { newState = STARTING_STATE; } else if (oldState == OPENED_STATE) { newState = LOADING_STATE; } else if (oldState == CLOSED_STATE) { newState = OPENING_STATE; } else { newState = oldState; } newStatus = newState & STATE_MASK | (newPhase << PHASE_SHIFT) & PHASE_MASK; } else { newState = oldState; newStatus = oldStatus; break; } } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if (oldState != newState) { if (newState == STARTING_STATE) { willStart(); convergeState(); } else if (newState == LOADING_STATE) { willLoad(); convergeState(); } else if (newState == OPENING_STATE) { willOpen(); convergeState(); } } } @Override public void stop() { int oldStatus; int newStatus; int oldState; int newState; int oldPhase; final int newPhase = LOADED_PHASE; do { oldStatus = this.status; oldState = oldStatus & STATE_MASK; oldPhase = (oldStatus & PHASE_MASK) >>> PHASE_SHIFT; if (newPhase < oldPhase) { if (oldState == STARTED_STATE) { newState = STOPPING_STATE; } else { newState = oldState; } newStatus = newState & STATE_MASK | (newPhase << PHASE_SHIFT) & PHASE_MASK; } else { newState = oldState; newStatus = oldStatus; break; } } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if (oldState != newState) { if (newState == STOPPING_STATE) { willStop(); convergeState(); } } } @Override public void unload() { int oldStatus; int newStatus; int oldState; int newState; int oldPhase; final int newPhase = OPENED_PHASE; do { oldStatus = this.status; oldState = oldStatus & STATE_MASK; oldPhase = (oldStatus & PHASE_MASK) >>> PHASE_SHIFT; if (newPhase < oldPhase) { if (oldState == LOADED_STATE) { newState = UNLOADING_STATE; } else if (oldState == STARTED_STATE) { newState = STOPPING_STATE; } else { newState = oldState; } newStatus = newState & STATE_MASK | (newPhase << PHASE_SHIFT) & PHASE_MASK; } else { newState = oldState; newStatus = oldStatus; break; } } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if (oldState != newState) { if (newState == UNLOADING_STATE) { willUnload(); convergeState(); } else if (newState == STOPPING_STATE) { willStop(); convergeState(); } } } @Override public void close() { int oldStatus; int newStatus; int oldState; int newState; int oldPhase; final int newPhase = CLOSED_PHASE; do { oldStatus = this.status; oldState = oldStatus & STATE_MASK; oldPhase = (oldStatus & PHASE_MASK) >>> PHASE_SHIFT; if (newPhase < oldPhase) { if (oldState == OPENED_STATE) { newState = CLOSING_STATE; } else if (oldState == LOADED_STATE) { newState = UNLOADING_STATE; } else if (oldState == STARTED_STATE) { newState = STOPPING_STATE; } else { newState = oldState; } newStatus = newState & STATE_MASK | (newPhase << PHASE_SHIFT) & PHASE_MASK; } else { newState = oldState; newStatus = oldStatus; break; } } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if (oldState != newState) { if (newState == CLOSING_STATE) { willClose(); convergeState(); } else if (newState == UNLOADING_STATE) { willUnload(); convergeState(); } else if (newState == STOPPING_STATE) { willStop(); convergeState(); } } } void convergeState() { call: do { int oldStatus; int newStatus; int oldState; int newState; loop: do { oldStatus = this.status; oldState = oldStatus & STATE_MASK; final int phase = (oldStatus & PHASE_MASK) >>> PHASE_SHIFT; switch (oldState) { case OPENING_STATE: newState = phase > OPENED_PHASE ? LOADING_STATE : phase < OPENED_PHASE ? CLOSING_STATE : OPENED_STATE; break; case LOADING_STATE: newState = phase > LOADED_PHASE ? STARTING_STATE : phase < LOADED_PHASE ? UNLOADING_STATE : LOADED_STATE; break; case STARTING_STATE: newState = phase < STARTED_PHASE ? STOPPING_STATE : STARTED_STATE; break; case STOPPING_STATE: newState = phase < LOADED_PHASE ? UNLOADING_STATE : phase > LOADED_PHASE ? STARTING_STATE : LOADED_STATE; break; case UNLOADING_STATE: newState = phase < OPENED_PHASE ? CLOSING_STATE : phase > OPENED_PHASE ? LOADING_STATE : OPENED_STATE; break; case CLOSING_STATE: newState = phase > CLOSED_PHASE ? OPENING_STATE : CLOSED_STATE; break; default: newState = oldState; newStatus = oldStatus; break loop; } newStatus = oldStatus & ~STATE_MASK | newState & STATE_MASK; } while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus)); if (oldState != newState) { switch (oldState) { case OPENING_STATE: didOpen(); break; case LOADING_STATE: didLoad(); break; case STARTING_STATE: didStart(); break; case STOPPING_STATE: didStop(); break; case UNLOADING_STATE: didUnload(); break; case CLOSING_STATE: final TierContext tierContext = tierContext(); if (tierContext != null) { tierContext.close(); } break; default: } switch (newState) { case OPENING_STATE: willOpen(); continue call; case LOADING_STATE: willLoad(); continue call; case STARTING_STATE: willStart(); continue call; case STOPPING_STATE: willStop(); continue call; case UNLOADING_STATE: willUnload(); continue call; case CLOSING_STATE: willClose(); continue call; default: break call; } } } while (true); } protected void willOpen() { final TierContext tierContext = tierContext(); if (tierContext != null) { tierContext.willOpen(); } } protected void didOpen() { final TierContext tierContext = tierContext(); if (tierContext != null) { tierContext.didOpen(); } } protected void willLoad() { final TierContext tierContext = tierContext(); if (tierContext != null) { tierContext.willLoad(); } } protected void didLoad() { final TierContext tierContext = tierContext(); if (tierContext != null) { tierContext.didLoad(); } } protected void willStart() { final TierContext tierContext = tierContext(); if (tierContext != null) { tierContext.willStart(); } } protected void didStart() { final TierContext tierContext = tierContext(); if (tierContext != null) { tierContext.didStart(); } } protected void willStop() { final TierContext tierContext = tierContext(); if (tierContext != null) { tierContext.willStop(); } } protected void didStop() { final TierContext tierContext = tierContext(); if (tierContext != null) { tierContext.didStop(); } } protected void willUnload() { final TierContext tierContext = tierContext(); if (tierContext != null) { tierContext.willUnload(); } } protected void didUnload() { final TierContext tierContext = tierContext(); if (tierContext != null) { tierContext.didUnload(); } } protected void willClose() { final TierContext tierContext = tierContext(); if (tierContext != null) { tierContext.willClose(); } } @Override public void didClose() { } @Override public void didFail(Throwable error) { } protected static final int STATE_MASK = 0xf; protected static final int CLOSED_STATE = 0; protected static final int CLOSING_STATE = 1; protected static final int UNLOADING_STATE = 2; protected static final int STOPPING_STATE = 3; protected static final int RECOVERING_STATE = 4; protected static final int FAILING_STATE = 5; protected static final int FAILED_STATE = 6; protected static final int OPENING_STATE = 7; protected static final int OPENED_STATE = 8; protected static final int LOADING_STATE = 9; protected static final int LOADED_STATE = 10; protected static final int STARTING_STATE = 11; protected static final int STARTED_STATE = 12; protected static final int PHASE_SHIFT = 4; protected static final int PHASE_MASK = 0xf << PHASE_SHIFT; protected static final int CLOSED_PHASE = 0; protected static final int OPENED_PHASE = 1; protected static final int LOADED_PHASE = 2; protected static final int STARTED_PHASE = 3; protected static final AtomicIntegerFieldUpdater<AbstractTierBinding> STATUS = AtomicIntegerFieldUpdater.newUpdater(AbstractTierBinding.class, "status"); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/AbstractUplinkContext.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import java.net.InetSocketAddress; import java.security.Principal; import java.security.cert.Certificate; import java.util.Collection; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import swim.api.Uplink; import swim.api.auth.Identity; import swim.collections.FingerTrieSeq; import swim.concurrent.Stage; import swim.structure.Value; import swim.uri.Uri; public abstract class AbstractUplinkContext implements LinkContext, Uplink { protected volatile Object observers; // Observer | Observer[] public abstract LaneBinding laneBinding(); @Override public abstract LinkBinding linkWrapper(); public abstract LinkBinding linkBinding(); @SuppressWarnings("unchecked") @Override public <T> T unwrapLink(Class<T> linkClass) { if (linkClass.isAssignableFrom(getClass())) { return (T) this; } else { return null; } } public abstract Stage stage(); @Override public abstract Uri hostUri(); @Override public abstract Uri nodeUri(); @Override public abstract Uri laneUri(); @Override public abstract Value linkKey(); @Override public boolean isConnectedUp() { return true; } @Override public boolean isRemoteUp() { return false; } @Override public boolean isSecureUp() { return true; } @Override public String securityProtocolUp() { return null; } @Override public String cipherSuiteUp() { return null; } @Override public InetSocketAddress localAddressUp() { return null; } @Override public Identity localIdentityUp() { return null; } @Override public Principal localPrincipalUp() { return null; } @Override public Collection<Certificate> localCertificatesUp() { return FingerTrieSeq.empty(); } @Override public InetSocketAddress remoteAddressUp() { return null; } @Override public Identity remoteIdentityUp() { return null; } @Override public Principal remotePrincipalUp() { return null; } @Override public Collection<Certificate> remoteCertificatesUp() { return FingerTrieSeq.empty(); } @Override public boolean isConnected() { return linkBinding().isConnectedDown(); } @Override public boolean isRemote() { return linkBinding().isRemoteDown(); } @Override public boolean isSecure() { return linkBinding().isSecureDown(); } @Override public String securityProtocol() { return linkBinding().securityProtocolDown(); } @Override public String cipherSuite() { return linkBinding().cipherSuiteDown(); } @Override public InetSocketAddress localAddress() { return linkBinding().localAddressDown(); } @Override public Identity localIdentity() { return linkBinding().localIdentityDown(); } @Override public Principal localPrincipal() { return linkBinding().localPrincipalDown(); } @Override public Collection<Certificate> localCertificates() { return linkBinding().localCertificatesDown(); } @Override public InetSocketAddress remoteAddress() { return linkBinding().remoteAddressDown(); } @Override public Identity remoteIdentity() { return linkBinding().remoteIdentityDown(); } @Override public Principal remotePrincipal() { return linkBinding().remotePrincipalDown(); } @Override public Collection<Certificate> remoteCertificates() { return linkBinding().remoteCertificatesDown(); } @Override public AbstractUplinkContext observe(Object newObserver) { do { final Object oldObservers = this.observers; final Object newObservers; if (oldObservers == null) { newObservers = newObserver; } else if (!(oldObservers instanceof Object[])) { final Object[] newArray = new Object[2]; newArray[0] = oldObservers; newArray[1] = newObserver; newObservers = newArray; } else { final Object[] oldArray = (Object[]) oldObservers; final int oldCount = oldArray.length; final Object[] newArray = new Object[oldCount + 1]; System.arraycopy(oldArray, 0, newArray, 0, oldCount); newArray[oldCount] = newObserver; newObservers = newArray; } if (OBSERVERS.compareAndSet(this, oldObservers, newObservers)) { break; } } while (true); return this; } @Override public AbstractUplinkContext unobserve(Object oldObserver) { do { final Object oldObservers = this.observers; final Object newObservers; if (oldObservers == null) { break; } else if (!(oldObservers instanceof Object[])) { if (oldObservers == oldObserver) { // found as sole observer newObservers = null; } else { break; // not found } } else { final Object[] oldArray = (Object[]) oldObservers; final int oldCount = oldArray.length; if (oldCount == 2) { if (oldArray[0] == oldObserver) { // found at index 0 newObservers = oldArray[1]; } else if (oldArray[1] == oldObserver) { // found at index 1 newObservers = oldArray[0]; } else { break; // not found } } else { int i = 0; while (i < oldCount) { if (oldArray[i] == oldObserver) { // found at index i break; } i += 1; } if (i < oldCount) { final Object[] newArray = new Object[oldCount - 1]; System.arraycopy(oldArray, 0, newArray, 0, i); System.arraycopy(oldArray, i + 1, newArray, i, oldCount - 1 - i); newObservers = newArray; } else { break; // not found } } } if (OBSERVERS.compareAndSet(this, oldObservers, newObservers)) { break; } } while (true); return this; } @Override public void closeUp() { laneBinding().closeUplink(linkKey()); } @Override public void close() { closeUp(); } @Override public void didOpenDown() { // stub } @Override public void didCloseDown() { // stub } protected void didFail(Throwable error) { laneBinding().didFail(error); } @Override public void traceUp(Object message) { laneBinding().trace(message); } @Override public void debugUp(Object message) { laneBinding().debug(message); } @Override public void infoUp(Object message) { laneBinding().info(message); } @Override public void warnUp(Object message) { laneBinding().warn(message); } @Override public void errorUp(Object message) { laneBinding().error(message); } @Override public void trace(Object message) { linkBinding().traceDown(message); } @Override public void debug(Object message) { linkBinding().debugDown(message); } @Override public void info(Object message) { linkBinding().infoDown(message); } @Override public void warn(Object message) { linkBinding().warnDown(message); } @Override public void error(Object message) { linkBinding().errorDown(message); } static final AtomicReferenceFieldUpdater<AbstractUplinkContext, Object> OBSERVERS = AtomicReferenceFieldUpdater.newUpdater(AbstractUplinkContext.class, Object.class, "observers"); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/CellBinding.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; public interface CellBinding { void openUplink(LinkBinding link); void pushUp(PushRequest pushRequest); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/CellContext.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.api.Downlink; import swim.api.policy.Policy; import swim.concurrent.Schedule; import swim.concurrent.Stage; import swim.store.StoreBinding; import swim.uri.Uri; import swim.util.Log; public interface CellContext extends Log { Uri meshUri(); Policy policy(); Schedule schedule(); Stage stage(); StoreBinding store(); LinkBinding bindDownlink(Downlink downlink); void openDownlink(LinkBinding link); void closeDownlink(LinkBinding link); void pushDown(PushRequest pushRequest); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/CellDef.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.concurrent.StageDef; import swim.store.StoreDef; public interface CellDef { LogDef logDef(); PolicyDef policyDef(); StageDef stageDef(); StoreDef storeDef(); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/DownlinkModel.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import swim.uri.Uri; public abstract class DownlinkModel<View extends DownlinkView> extends AbstractDownlinkBinding implements LinkBinding { protected volatile Object views; // View | DownlinkView[] public DownlinkModel(Uri meshUri, Uri hostUri, Uri nodeUri, Uri laneUri) { super(meshUri, hostUri, nodeUri, laneUri); } public void addDownlink(View view) { Object oldViews; Object newViews; do { oldViews = this.views; if (oldViews instanceof DownlinkView) { newViews = new DownlinkView[]{(DownlinkView) oldViews, view}; } else if (oldViews instanceof DownlinkView[]) { final DownlinkView[] oldViewArray = (DownlinkView[]) oldViews; final int n = oldViewArray.length; final DownlinkView[] newViewArray = new DownlinkView[n + 1]; System.arraycopy(oldViewArray, 0, newViewArray, 0, n); newViewArray[n] = view; newViews = newViewArray; } else { newViews = view; } } while (!VIEWS.compareAndSet(this, oldViews, newViews)); didAddDownlink(view); if (oldViews == null) { openDown(); } } public void removeDownlink(View view) { Object oldViews; Object newViews; do { oldViews = this.views; if (oldViews instanceof DownlinkView) { if (oldViews == view) { newViews = null; continue; } } else if (oldViews instanceof DownlinkView[]) { final DownlinkView[] oldViewArray = (DownlinkView[]) oldViews; final int n = oldViewArray.length; if (n == 2) { if (oldViewArray[0] == view) { newViews = oldViewArray[1]; continue; } else if (oldViewArray[1] == view) { newViews = oldViewArray[0]; continue; } } else { // n > 2 final DownlinkView[] newViewArray = new DownlinkView[n - 1]; int i = 0; while (i < n) { if (oldViewArray[i] != view) { if (i < n - 1) { newViewArray[i] = oldViewArray[i]; } i += 1; } else { break; } } if (i < n) { System.arraycopy(oldViewArray, i + 1, newViewArray, i, n - (i + 1)); newViews = newViewArray; continue; } } } newViews = oldViews; break; } while (!VIEWS.compareAndSet(this, oldViews, newViews)); if (oldViews != newViews) { didRemoveDownlink(view); } if (newViews == null) { closeDown(); } } protected void didAddDownlink(View view) { // stub } protected void didRemoveDownlink(View view) { // stub } @SuppressWarnings("unchecked") @Override public void reopen() { final Object views = VIEWS.getAndSet(this, null); View view; if (views instanceof DownlinkView) { view = (View) views; view.close(); didRemoveDownlink(view); closeDown(); view.open(); } else if (views instanceof DownlinkView[]) { final DownlinkView[] viewArray = (DownlinkView[]) views; final int n = viewArray.length; for (int i = 0; i < n; i += 1) { view = (View) viewArray[i]; view.close(); didRemoveDownlink(view); } closeDown(); for (int i = 0; i < n; i += 1) { view = (View) viewArray[i]; view.open(); } } } @Override public void didConnect() { new DownlinkRelayDidConnect<View>(this).run(); } @Override public void didDisconnect() { new DownlinkRelayDidDisconnect<View>(this).run(); } @Override public void didCloseUp() { new DownlinkRelayDidClose<View>(this).run(); } @Override public void didFail(Throwable error) { new DownlinkRelayDidFail<View>(this, error).run(); } @SuppressWarnings("unchecked") static final AtomicReferenceFieldUpdater<DownlinkModel<?>, Object> VIEWS = AtomicReferenceFieldUpdater.newUpdater((Class<DownlinkModel<?>>) (Class<?>) DownlinkModel.class, Object.class, "views"); } final class DownlinkRelayDidConnect<View extends DownlinkView> extends DownlinkRelay<DownlinkModel<View>, View> { DownlinkRelayDidConnect(DownlinkModel<View> model) { super(model); } @Override protected boolean runPhase(View view, int phase, boolean preemptive) { if (phase == 0) { if (preemptive) { view.downlinkDidConnect(); } return view.dispatchDidConnect(preemptive); } else { throw new AssertionError(); // unreachable } } } final class DownlinkRelayDidDisconnect<View extends DownlinkView> extends DownlinkRelay<DownlinkModel<View>, View> { DownlinkRelayDidDisconnect(DownlinkModel<View> model) { super(model); } @Override protected boolean runPhase(View view, int phase, boolean preemptive) { if (phase == 0) { if (preemptive) { view.downlinkDidDisconnect(); } return view.dispatchDidDisconnect(preemptive); } else { throw new AssertionError(); // unreachable } } } final class DownlinkRelayDidClose<View extends DownlinkView> extends DownlinkRelay<DownlinkModel<View>, View> { DownlinkRelayDidClose(DownlinkModel<View> model) { super(model); } @Override protected boolean runPhase(View view, int phase, boolean preemptive) { if (phase == 0) { if (preemptive) { view.downlinkDidClose(); } return view.dispatchDidClose(preemptive); } else { throw new AssertionError(); // unreachable } } } final class DownlinkRelayDidFail<View extends DownlinkView> extends DownlinkRelay<DownlinkModel<View>, View> { final Throwable error; DownlinkRelayDidFail(DownlinkModel<View> model, Throwable error) { super(model); this.error = error; } @Override protected boolean runPhase(View view, int phase, boolean preemptive) { if (phase == 0) { if (preemptive) { view.downlinkDidFail(this.error); } return view.dispatchDidFail(this.error, preemptive); } else { throw new AssertionError(); // unreachable } } }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/DownlinkRelay.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.concurrent.Conts; import swim.concurrent.Stage; public abstract class DownlinkRelay<Model extends DownlinkModel<View>, View extends DownlinkView> implements Runnable { protected final Model model; protected final Object views; // View | View[] protected int viewIndex; protected final int viewCount; protected int phase; protected final int phaseCount; protected boolean preemptive; protected Stage stage; protected DownlinkRelay(Model model, int minPhase, int phaseCount, Stage stage) { this.model = model; this.views = model.views; if (this.views instanceof DownlinkView) { this.viewCount = 1; } else if (this.views instanceof DownlinkView[]) { this.viewCount = ((DownlinkView[]) views).length; } else { this.viewCount = 0; } this.phase = minPhase; this.phaseCount = phaseCount; this.preemptive = true; this.stage = stage; beginPhase(phase); } protected DownlinkRelay(Model model, int phaseCount) { this(model, 0, phaseCount, null); } protected DownlinkRelay(Model model) { this(model, 0, 1, null); } public boolean isDone() { return this.phase > this.phaseCount; } protected void beginPhase(int phase) { // stub } protected boolean runPhase(View view, int phase, boolean preemptive) { return true; } protected void endPhase(int phase) { // stub } protected void done() { // stub } void pass(View view) { do { if (this.viewIndex < this.viewCount) { try { if (!runPhase(view, this.phase, this.preemptive) && this.preemptive) { this.preemptive = false; if (this.stage != view.stage) { this.stage = view.stage; this.stage.execute(this); return; } else { continue; } } } catch (Throwable error) { if (Conts.isNonFatal(error)) { view.downlinkDidFail(error); } throw error; } this.viewIndex += 1; } else if (this.phase < this.phaseCount) { endPhase(this.phase); this.viewIndex = 0; this.phase += 1; this.preemptive = true; if (this.phase < this.phaseCount) { beginPhase(this.phase); } else { endPhase(this.phase); this.phase += 1; done(); return; } } else { return; } } while (true); } @SuppressWarnings("unchecked") void pass(DownlinkView[] views) { do { if (this.viewIndex < this.viewCount) { final View view = (View) views[this.viewIndex]; try { if (!runPhase(view, this.phase, this.preemptive) && this.preemptive) { this.preemptive = false; if (this.stage != view.stage) { this.stage = view.stage; this.stage.execute(this); return; } else { continue; } } } catch (Throwable error) { if (Conts.isNonFatal(error)) { view.downlinkDidFail(error); } throw error; } this.viewIndex += 1; } else if (this.phase < this.phaseCount) { endPhase(this.phase); this.viewIndex = 0; this.phase += 1; this.preemptive = true; if (this.phase < this.phaseCount) { beginPhase(this.phase); } else { endPhase(this.phase); this.phase += 1; done(); return; } } else { return; } } while (true); } @SuppressWarnings("unchecked") @Override public void run() { try { if (this.viewCount == 1) { pass((View) views); } else if (this.viewCount > 1) { pass((DownlinkView[]) views); } } catch (Throwable error) { if (Conts.isNonFatal(error)) { this.model.didFail(error); } else { throw error; } } } }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/DownlinkView.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import java.net.InetSocketAddress; import java.security.Principal; import java.security.cert.Certificate; import java.util.Collection; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import swim.api.Downlink; import swim.api.Link; import swim.api.SwimContext; import swim.api.auth.Identity; import swim.api.function.DidClose; import swim.api.function.DidConnect; import swim.api.function.DidDisconnect; import swim.api.function.DidFail; import swim.collections.FingerTrieSeq; import swim.concurrent.Conts; import swim.concurrent.Stage; public abstract class DownlinkView implements Downlink { protected final CellContext cellContext; protected final Stage stage; protected volatile Object observers; // Observer | Observer[] public DownlinkView(CellContext cellContext, Stage stage, Object observers) { this.cellContext = cellContext; this.stage = stage; this.observers = observers; } public final CellContext cellContext() { return this.cellContext; } public abstract DownlinkModel<?> downlinkModel(); public final Stage stage() { return this.stage; } @Override public boolean isConnected() { final DownlinkModel<?> model = downlinkModel(); return model != null && model.isConnected(); } @Override public boolean isRemote() { final DownlinkModel<?> model = downlinkModel(); return model != null && model.isRemote(); } @Override public boolean isSecure() { final DownlinkModel<?> model = downlinkModel(); return model != null && model.isSecure(); } @Override public String securityProtocol() { final DownlinkModel<?> model = downlinkModel(); if (model != null) { return model.securityProtocol(); } else { return null; } } @Override public String cipherSuite() { final DownlinkModel<?> model = downlinkModel(); if (model != null) { return model.cipherSuite(); } else { return null; } } @Override public InetSocketAddress localAddress() { final DownlinkModel<?> model = downlinkModel(); if (model != null) { return model.localAddress(); } else { return null; } } @Override public Identity localIdentity() { final DownlinkModel<?> model = downlinkModel(); if (model != null) { return model.localIdentity(); } else { return null; } } @Override public Principal localPrincipal() { final DownlinkModel<?> model = downlinkModel(); if (model != null) { return model.localPrincipal(); } else { return null; } } @Override public Collection<Certificate> localCertificates() { final DownlinkModel<?> model = downlinkModel(); if (model != null) { return model.localCertificates(); } else { return FingerTrieSeq.empty(); } } @Override public InetSocketAddress remoteAddress() { final DownlinkModel<?> model = downlinkModel(); if (model != null) { return model.remoteAddress(); } else { return null; } } @Override public Identity remoteIdentity() { final DownlinkModel<?> model = downlinkModel(); if (model != null) { return model.remoteIdentity(); } else { return null; } } @Override public Principal remotePrincipal() { final DownlinkModel<?> model = downlinkModel(); if (model != null) { return model.remotePrincipal(); } else { return null; } } @Override public Collection<Certificate> remoteCertificates() { final DownlinkModel<?> model = downlinkModel(); if (model != null) { return model.remoteCertificates(); } else { return FingerTrieSeq.empty(); } } @Override public DownlinkView observe(Object newObserver) { do { final Object oldObservers = this.observers; final Object newObservers; if (oldObservers == null) { newObservers = newObserver; } else if (!(oldObservers instanceof Object[])) { final Object[] newArray = new Object[2]; newArray[0] = oldObservers; newArray[1] = newObserver; newObservers = newArray; } else { final Object[] oldArray = (Object[]) oldObservers; final int oldCount = oldArray.length; final Object[] newArray = new Object[oldCount + 1]; System.arraycopy(oldArray, 0, newArray, 0, oldCount); newArray[oldCount] = newObserver; newObservers = newArray; } if (OBSERVERS.compareAndSet(this, oldObservers, newObservers)) { break; } } while (true); return this; } @Override public DownlinkView unobserve(Object oldObserver) { do { final Object oldObservers = this.observers; final Object newObservers; if (oldObservers == null) { break; } else if (!(oldObservers instanceof Object[])) { if (oldObservers == oldObserver) { // found as sole observer newObservers = null; } else { break; // not found } } else { final Object[] oldArray = (Object[]) oldObservers; final int oldCount = oldArray.length; if (oldCount == 2) { if (oldArray[0] == oldObserver) { // found at index 0 newObservers = oldArray[1]; } else if (oldArray[1] == oldObserver) { // found at index 1 newObservers = oldArray[0]; } else { break; // not found } } else { int i = 0; while (i < oldCount) { if (oldArray[i] == oldObserver) { // found at index i break; } i += 1; } if (i < oldCount) { final Object[] newArray = new Object[oldCount - 1]; System.arraycopy(oldArray, 0, newArray, 0, i); System.arraycopy(oldArray, i + 1, newArray, i, oldCount - 1 - i); newObservers = newArray; } else { break; // not found } } } if (OBSERVERS.compareAndSet(this, oldObservers, newObservers)) { break; } } while (true); return this; } @Override public abstract DownlinkView didConnect(DidConnect didConnect); @Override public abstract DownlinkView didDisconnect(DidDisconnect didDisconnect); @Override public abstract DownlinkView didClose(DidClose didClose); @Override public abstract DownlinkView didFail(DidFail didFail); public boolean dispatchDidConnect(boolean preemptive) { final Link oldLink = SwimContext.getLink(); try { SwimContext.setLink(this); final Object observers = this.observers; boolean complete = true; if (observers instanceof DidConnect) { if (((DidConnect) observers).isPreemptive() == preemptive) { try { ((DidConnect) observers).didConnect(); } catch (Throwable error) { if (Conts.isNonFatal(error)) { downlinkDidFail(error); } throw error; } } else if (preemptive) { complete = false; } } else if (observers instanceof Object[]) { final Object[] array = (Object[]) observers; for (int i = 0, n = array.length; i < n; i += 1) { final Object observer = array[i]; if (observer instanceof DidConnect) { if (((DidConnect) observer).isPreemptive() == preemptive) { try { ((DidConnect) observer).didConnect(); } catch (Throwable error) { if (Conts.isNonFatal(error)) { downlinkDidFail(error); } throw error; } } else if (preemptive) { complete = false; } } } } return complete; } finally { SwimContext.setLink(oldLink); } } public boolean dispatchDidDisconnect(boolean preemptive) { final Link oldLink = SwimContext.getLink(); try { SwimContext.setLink(this); final Object observers = this.observers; boolean complete = true; if (observers instanceof DidDisconnect) { if (((DidDisconnect) observers).isPreemptive() == preemptive) { try { ((DidDisconnect) observers).didDisconnect(); } catch (Throwable error) { if (Conts.isNonFatal(error)) { downlinkDidFail(error); } throw error; } } else if (preemptive) { complete = false; } } else if (observers instanceof Object[]) { final Object[] array = (Object[]) observers; for (int i = 0, n = array.length; i < n; i += 1) { final Object observer = array[i]; if (observer instanceof DidDisconnect) { if (((DidDisconnect) observer).isPreemptive() == preemptive) { try { ((DidDisconnect) observer).didDisconnect(); } catch (Throwable error) { if (Conts.isNonFatal(error)) { downlinkDidFail(error); } throw error; } } else if (preemptive) { complete = false; } } } } return complete; } finally { SwimContext.setLink(oldLink); } } public boolean dispatchDidClose(boolean preemptive) { final Link oldLink = SwimContext.getLink(); try { SwimContext.setLink(this); final Object observers = this.observers; boolean complete = true; if (observers instanceof DidClose) { if (((DidClose) observers).isPreemptive() == preemptive) { try { ((DidClose) observers).didClose(); } catch (Throwable error) { if (Conts.isNonFatal(error)) { downlinkDidFail(error); } throw error; } } else if (preemptive) { complete = false; } } else if (observers instanceof Object[]) { final Object[] array = (Object[]) observers; for (int i = 0, n = array.length; i < n; i += 1) { final Object observer = array[i]; if (observer instanceof DidClose) { if (((DidClose) observer).isPreemptive() == preemptive) { try { ((DidClose) observer).didClose(); } catch (Throwable error) { if (Conts.isNonFatal(error)) { downlinkDidFail(error); } throw error; } } else if (preemptive) { complete = false; } } } } return complete; } finally { SwimContext.setLink(oldLink); } } public boolean dispatchDidFail(Throwable cause, boolean preemptive) { final Link oldLink = SwimContext.getLink(); try { SwimContext.setLink(this); final Object observers = this.observers; boolean complete = true; if (observers instanceof DidFail) { if (((DidFail) observers).isPreemptive() == preemptive) { try { ((DidFail) observers).didFail(cause); } catch (Throwable error) { if (Conts.isNonFatal(error)) { downlinkDidFail(error); } throw error; } } else if (preemptive) { complete = false; } } else if (observers instanceof Object[]) { final Object[] array = (Object[]) observers; for (int i = 0, n = array.length; i < n; i += 1) { final Object observer = array[i]; if (observer instanceof DidFail) { if (((DidFail) observer).isPreemptive() == preemptive) { try { ((DidFail) observer).didFail(cause); } catch (Throwable error) { if (Conts.isNonFatal(error)) { downlinkDidFail(error); } throw error; } } else if (preemptive) { complete = false; } } } } return complete; } finally { SwimContext.setLink(oldLink); } } public void downlinkDidConnect() { // stub } public void downlinkDidDisconnect() { // stub } public void downlinkDidClose() { // stub } public void downlinkDidFail(Throwable error) { // stub } public abstract DownlinkModel<?> createDownlinkModel(); @Override public abstract DownlinkView open(); @SuppressWarnings("unchecked") @Override public void close() { ((DownlinkModel<DownlinkView>) downlinkModel()).removeDownlink(this); } @Override public void trace(Object message) { final DownlinkModel<?> model = downlinkModel(); if (model != null) { model.trace(message); } } @Override public void debug(Object message) { final DownlinkModel<?> model = downlinkModel(); if (model != null) { model.debug(message); } } @Override public void info(Object message) { final DownlinkModel<?> model = downlinkModel(); if (model != null) { model.info(message); } } @Override public void warn(Object message) { final DownlinkModel<?> model = downlinkModel(); if (model != null) { model.warn(message); } } @Override public void error(Object message) { final DownlinkModel<?> model = downlinkModel(); if (model != null) { model.error(message); } } static final AtomicReferenceFieldUpdater<DownlinkView, Object> OBSERVERS = AtomicReferenceFieldUpdater.newUpdater(DownlinkView.class, Object.class, "observers"); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/EdgeBinding.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.collections.HashTrieMap; import swim.uri.Uri; public interface EdgeBinding extends TierBinding, CellBinding, CellContext { EdgeBinding edgeWrapper(); EdgeContext edgeContext(); void setEdgeContext(EdgeContext edgeContext); <T> T unwrapEdge(Class<T> edgeClass); MeshBinding network(); void setNetwork(MeshBinding network); HashTrieMap<Uri, MeshBinding> meshes(); MeshBinding getMesh(Uri meshUri); MeshBinding openMesh(Uri meshUri); MeshBinding openMesh(Uri meshUri, MeshBinding mesh); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/EdgeContext.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.api.agent.Agent; import swim.api.agent.AgentDef; import swim.api.agent.AgentFactory; import swim.api.auth.Credentials; import swim.api.auth.Identity; import swim.api.policy.PolicyDirective; import swim.structure.Value; import swim.uri.Uri; public interface EdgeContext extends TierContext, CellContext { EdgeBinding edgeWrapper(); <T> T unwrapEdge(Class<T> edgeClass); MeshBinding createMesh(Uri meshUri); MeshBinding injectMesh(Uri meshUri, MeshBinding mesh); PartBinding createPart(Uri meshUri, Value partKey); PartBinding injectPart(Uri meshUri, Value partKey, PartBinding part); HostBinding createHost(Uri meshUri, Value partKey, Uri hostUri); HostBinding injectHost(Uri meshUri, Value partKey, Uri hostUri, HostBinding host); NodeBinding createNode(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri); NodeBinding injectNode(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, NodeBinding node); LaneBinding createLane(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, LaneDef laneDef); LaneBinding createLane(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri); LaneBinding injectLane(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri, LaneBinding lane); void openLanes(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, NodeBinding node); AgentFactory<?> createAgentFactory(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, AgentDef agentDef); <A extends Agent> AgentFactory<A> createAgentFactory(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, Class<? extends A> agentClass); void openAgents(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, NodeBinding node); PolicyDirective<Identity> authenticate(Credentials credentials); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/EdgeDef.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import java.util.Collection; import swim.structure.Value; import swim.uri.Uri; public interface EdgeDef extends CellDef { Collection<? extends MeshDef> meshDefs(); MeshDef getMeshDef(Uri meshUri); Collection<? extends PartDef> partDefs(); PartDef getPartDef(Value partKey); Collection<? extends HostDef> hostDefs(); HostDef getHostDef(Uri hostUri); Collection<? extends NodeDef> nodeDefs(); NodeDef getNodeDef(Uri nodeUri); Collection<? extends LaneDef> laneDefs(); LaneDef getLaneDef(Uri laneUri); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/EdgeProxy.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.api.Downlink; import swim.api.agent.Agent; import swim.api.agent.AgentDef; import swim.api.agent.AgentFactory; import swim.api.auth.Credentials; import swim.api.auth.Identity; import swim.api.policy.Policy; import swim.api.policy.PolicyDirective; import swim.collections.HashTrieMap; import swim.concurrent.Schedule; import swim.concurrent.Stage; import swim.store.StoreBinding; import swim.structure.Value; import swim.uri.Uri; public class EdgeProxy implements EdgeBinding, EdgeContext { protected final EdgeBinding edgeBinding; protected EdgeContext edgeContext; public EdgeProxy(EdgeBinding edgeBinding) { this.edgeBinding = edgeBinding; } @Override public final TierContext tierContext() { return this; } @Override public final EdgeBinding edgeWrapper() { return this.edgeBinding.edgeWrapper(); } public final EdgeBinding edgeBinding() { return this.edgeBinding; } @Override public final EdgeContext edgeContext() { return this.edgeContext; } @Override public void setEdgeContext(EdgeContext edgeContext) { this.edgeContext = edgeContext; this.edgeBinding.setEdgeContext(this); } @SuppressWarnings("unchecked") @Override public <T> T unwrapEdge(Class<T> edgeClass) { if (edgeClass.isAssignableFrom(getClass())) { return (T) this; } else { return this.edgeContext.unwrapEdge(edgeClass); } } @Override public Uri meshUri() { return this.edgeContext.meshUri(); } @Override public Policy policy() { return this.edgeContext.policy(); } @Override public Schedule schedule() { return this.edgeContext.schedule(); } @Override public Stage stage() { return this.edgeContext.stage(); } @Override public StoreBinding store() { return this.edgeContext.store(); } @Override public MeshBinding network() { return this.edgeBinding.network(); } @Override public void setNetwork(MeshBinding network) { this.edgeBinding.setNetwork(network); } @Override public HashTrieMap<Uri, MeshBinding> meshes() { return this.edgeBinding.meshes(); } @Override public MeshBinding getMesh(Uri meshUri) { return this.edgeBinding.getMesh(meshUri); } @Override public MeshBinding openMesh(Uri meshUri) { return this.edgeBinding.openMesh(meshUri); } @Override public MeshBinding openMesh(Uri meshUri, MeshBinding mesh) { return this.edgeBinding.openMesh(meshUri, mesh); } @Override public MeshBinding createMesh(Uri meshUri) { return this.edgeContext.createMesh(meshUri); } @Override public MeshBinding injectMesh(Uri meshUri, MeshBinding mesh) { return this.edgeContext.injectMesh(meshUri, mesh); } @Override public PartBinding createPart(Uri meshUri, Value partKey) { return this.edgeContext.createPart(meshUri, partKey); } @Override public PartBinding injectPart(Uri meshUri, Value partKey, PartBinding part) { return this.edgeContext.injectPart(meshUri, partKey, part); } @Override public HostBinding createHost(Uri meshUri, Value partKey, Uri hostUri) { return this.edgeContext.createHost(meshUri, partKey, hostUri); } @Override public HostBinding injectHost(Uri meshUri, Value partKey, Uri hostUri, HostBinding host) { return this.edgeContext.injectHost(meshUri, partKey, hostUri, host); } @Override public NodeBinding createNode(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri) { return this.edgeContext.createNode(meshUri, partKey, hostUri, nodeUri); } @Override public NodeBinding injectNode(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, NodeBinding node) { return this.edgeContext.injectNode(meshUri, partKey, hostUri, nodeUri, node); } @Override public LaneBinding createLane(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, LaneDef laneDef) { return this.edgeContext.createLane(meshUri, partKey, hostUri, nodeUri, laneDef); } @Override public LaneBinding createLane(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri) { return this.edgeContext.createLane(meshUri, partKey, hostUri, nodeUri, laneUri); } @Override public LaneBinding injectLane(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri, LaneBinding lane) { return this.edgeContext.injectLane(meshUri, partKey, hostUri, nodeUri, laneUri, lane); } @Override public void openLanes(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, NodeBinding node) { this.edgeContext.openLanes(meshUri, partKey, hostUri, nodeUri, node); } @Override public AgentFactory<?> createAgentFactory(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, AgentDef agentDef) { return this.edgeContext.createAgentFactory(meshUri, partKey, hostUri, nodeUri, agentDef); } @Override public <A extends Agent> AgentFactory<A> createAgentFactory(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, Class<? extends A> agentClass) { return this.edgeContext.createAgentFactory(meshUri, partKey, hostUri, nodeUri, agentClass); } @Override public void openAgents(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, NodeBinding node) { this.edgeContext.openAgents(meshUri, partKey, hostUri, nodeUri, node); } @Override public PolicyDirective<Identity> authenticate(Credentials credentials) { return this.edgeContext.authenticate(credentials); } @Override public LinkBinding bindDownlink(Downlink downlink) { return this.edgeBinding.bindDownlink(downlink); } @Override public void openDownlink(LinkBinding link) { this.edgeBinding.openDownlink(link); } @Override public void closeDownlink(LinkBinding link) { this.edgeBinding.closeDownlink(link); } @Override public void pushDown(PushRequest pushRequest) { this.edgeBinding.pushDown(pushRequest); } @Override public void openUplink(LinkBinding link) { this.edgeBinding.openUplink(link); } @Override public void pushUp(PushRequest pushRequest) { this.edgeBinding.pushUp(pushRequest); } @Override public void trace(Object message) { this.edgeContext.trace(message); } @Override public void debug(Object message) { this.edgeContext.debug(message); } @Override public void info(Object message) { this.edgeContext.info(message); } @Override public void warn(Object message) { this.edgeContext.warn(message); } @Override public void error(Object message) { this.edgeContext.error(message); } @Override public boolean isClosed() { return this.edgeBinding.isClosed(); } @Override public boolean isOpened() { return this.edgeBinding.isOpened(); } @Override public boolean isLoaded() { return this.edgeBinding.isLoaded(); } @Override public boolean isStarted() { return this.edgeBinding.isStarted(); } @Override public void open() { this.edgeBinding.open(); } @Override public void load() { this.edgeBinding.load(); } @Override public void start() { this.edgeBinding.start(); } @Override public void stop() { this.edgeBinding.stop(); } @Override public void unload() { this.edgeBinding.unload(); } @Override public void close() { this.edgeBinding.close(); } @Override public void willOpen() { this.edgeContext.willOpen(); } @Override public void didOpen() { this.edgeContext.didOpen(); } @Override public void willLoad() { this.edgeContext.willLoad(); } @Override public void didLoad() { this.edgeContext.didLoad(); } @Override public void willStart() { this.edgeContext.willStart(); } @Override public void didStart() { this.edgeContext.didStart(); } @Override public void willStop() { this.edgeContext.willStop(); } @Override public void didStop() { this.edgeContext.didStop(); } @Override public void willUnload() { this.edgeContext.willUnload(); } @Override public void didUnload() { this.edgeContext.didUnload(); } @Override public void willClose() { this.edgeContext.willClose(); } @Override public void didClose() { this.edgeBinding.didClose(); } @Override public void didFail(Throwable error) { this.edgeBinding.didFail(error); } }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/HostBinding.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.collections.HashTrieMap; import swim.structure.Value; import swim.uri.Uri; public interface HostBinding extends TierBinding, CellBinding { PartBinding part(); HostBinding hostWrapper(); HostContext hostContext(); void setHostContext(HostContext hostContext); <T> T unwrapHost(Class<T> hostClass); Uri meshUri(); Value partKey(); Uri hostUri(); boolean isConnected(); boolean isRemote(); boolean isSecure(); boolean isPrimary(); void setPrimary(boolean isPrimary); boolean isReplica(); void setReplica(boolean isReplica); boolean isMaster(); boolean isSlave(); void didBecomeMaster(); void didBecomeSlave(); HashTrieMap<Uri, NodeBinding> nodes(); NodeBinding getNode(Uri nodeUri); NodeBinding openNode(Uri nodeUri); NodeBinding openNode(Uri nodeUri, NodeBinding node); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/HostContext.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.api.agent.Agent; import swim.api.agent.AgentDef; import swim.api.agent.AgentFactory; import swim.api.auth.Credentials; import swim.api.auth.Identity; import swim.api.policy.PolicyDirective; import swim.structure.Value; import swim.uri.Uri; public interface HostContext extends TierContext, CellContext { PartBinding part(); HostBinding hostWrapper(); <T> T unwrapHost(Class<T> hostClass); @Override Uri meshUri(); Value partKey(); Uri hostUri(); NodeBinding createNode(Uri nodeUri); NodeBinding injectNode(Uri nodeUri, NodeBinding node); LaneBinding createLane(Uri nodeUri, LaneDef laneDef); LaneBinding createLane(Uri nodeUri, Uri laneUri); LaneBinding injectLane(Uri nodeUri, Uri laneUri, LaneBinding lane); void openLanes(Uri nodeUri, NodeBinding node); AgentFactory<?> createAgentFactory(Uri nodeUri, AgentDef agentDef); <A extends Agent> AgentFactory<A> createAgentFactory(Uri nodeUri, Class<? extends A> agentClass); void openAgents(Uri nodeUri, NodeBinding node); PolicyDirective<Identity> authenticate(Credentials credentials); void didConnect(); void didDisconnect(); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/HostDef.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import java.util.Collection; import swim.uri.Uri; import swim.uri.UriPattern; public interface HostDef extends CellDef { Uri hostUri(); UriPattern hostPattern(); boolean isPrimary(); boolean isReplica(); Collection<? extends NodeDef> nodeDefs(); NodeDef getNodeDef(Uri nodeUri); Collection<? extends LaneDef> laneDefs(); LaneDef getLaneDef(Uri laneUri); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/HostProxy.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.api.Downlink; import swim.api.agent.Agent; import swim.api.agent.AgentDef; import swim.api.agent.AgentFactory; import swim.api.auth.Credentials; import swim.api.auth.Identity; import swim.api.policy.Policy; import swim.api.policy.PolicyDirective; import swim.collections.HashTrieMap; import swim.concurrent.Schedule; import swim.concurrent.Stage; import swim.store.StoreBinding; import swim.structure.Value; import swim.uri.Uri; public class HostProxy implements HostBinding, HostContext { protected final HostBinding hostBinding; protected HostContext hostContext; public HostProxy(HostBinding hostBinding) { this.hostBinding = hostBinding; } @Override public final TierContext tierContext() { return this; } @Override public final PartBinding part() { return this.hostContext.part(); } @Override public final HostBinding hostWrapper() { return this.hostBinding.hostWrapper(); } public final HostBinding hostBinding() { return this.hostBinding; } @Override public final HostContext hostContext() { return hostContext; } @Override public void setHostContext(HostContext hostContext) { this.hostContext = hostContext; this.hostBinding.setHostContext(this); } @SuppressWarnings("unchecked") @Override public <T> T unwrapHost(Class<T> hostClass) { if (hostClass.isAssignableFrom(getClass())) { return (T) this; } else { return this.hostContext.unwrapHost(hostClass); } } @Override public Uri meshUri() { return this.hostContext.meshUri(); } @Override public Value partKey() { return this.hostContext.partKey(); } @Override public Uri hostUri() { return this.hostContext.hostUri(); } @Override public Policy policy() { return this.hostContext.policy(); } @Override public Schedule schedule() { return this.hostContext.schedule(); } @Override public Stage stage() { return this.hostContext.stage(); } @Override public StoreBinding store() { return this.hostContext.store(); } @Override public boolean isConnected() { return this.hostBinding.isConnected(); } @Override public boolean isRemote() { return this.hostBinding.isRemote(); } @Override public boolean isSecure() { return this.hostBinding.isSecure(); } @Override public boolean isPrimary() { return this.hostBinding.isPrimary(); } @Override public void setPrimary(boolean isPrimary) { this.hostBinding.setPrimary(isPrimary); } @Override public boolean isReplica() { return this.hostBinding.isReplica(); } @Override public void setReplica(boolean isReplica) { this.hostBinding.setReplica(isReplica); } @Override public boolean isMaster() { return this.hostBinding.isMaster(); } @Override public boolean isSlave() { return this.hostBinding.isSlave(); } @Override public void didBecomeMaster() { this.hostBinding.didBecomeMaster(); } @Override public void didBecomeSlave() { this.hostBinding.didBecomeSlave(); } @Override public HashTrieMap<Uri, NodeBinding> nodes() { return this.hostBinding.nodes(); } @Override public NodeBinding getNode(Uri nodeUri) { return this.hostBinding.getNode(nodeUri); } @Override public NodeBinding openNode(Uri nodeUri) { return this.hostBinding.openNode(nodeUri); } @Override public NodeBinding openNode(Uri nodeUri, NodeBinding node) { return this.hostBinding.openNode(nodeUri, node); } @Override public NodeBinding createNode(Uri nodeUri) { return this.hostContext.createNode(nodeUri); } @Override public NodeBinding injectNode(Uri nodeUri, NodeBinding node) { return this.hostContext.injectNode(nodeUri, node); } @Override public LaneBinding createLane(Uri nodeUri, LaneDef laneDef) { return this.hostContext.createLane(nodeUri, laneDef); } @Override public LaneBinding createLane(Uri nodeUri, Uri laneUri) { return this.hostContext.createLane(nodeUri, laneUri); } @Override public LaneBinding injectLane(Uri nodeUri, Uri laneUri, LaneBinding lane) { return this.hostContext.injectLane(nodeUri, laneUri, lane); } @Override public void openLanes(Uri nodeUri, NodeBinding node) { this.hostContext.openLanes(nodeUri, node); } @Override public AgentFactory<?> createAgentFactory(Uri nodeUri, AgentDef agentDef) { return this.hostContext.createAgentFactory(nodeUri, agentDef); } @Override public <A extends Agent> AgentFactory<A> createAgentFactory(Uri nodeUri, Class<? extends A> agentClass) { return this.hostContext.createAgentFactory(nodeUri, agentClass); } @Override public void openAgents(Uri nodeUri, NodeBinding node) { this.hostContext.openAgents(nodeUri, node); } @Override public PolicyDirective<Identity> authenticate(Credentials credentials) { return this.hostContext.authenticate(credentials); } @Override public LinkBinding bindDownlink(Downlink downlink) { return this.hostContext.bindDownlink(downlink); } @Override public void openDownlink(LinkBinding link) { this.hostContext.openDownlink(link); } @Override public void closeDownlink(LinkBinding link) { this.hostContext.closeDownlink(link); } @Override public void pushDown(PushRequest pushRequest) { this.hostContext.pushDown(pushRequest); } @Override public void openUplink(LinkBinding link) { this.hostBinding.openUplink(link); } @Override public void pushUp(PushRequest pushRequest) { this.hostBinding.pushUp(pushRequest); } @Override public void trace(Object message) { this.hostContext.trace(message); } @Override public void debug(Object message) { this.hostContext.debug(message); } @Override public void info(Object message) { this.hostContext.info(message); } @Override public void warn(Object message) { this.hostContext.warn(message); } @Override public void error(Object message) { this.hostContext.error(message); } @Override public boolean isClosed() { return this.hostBinding.isClosed(); } @Override public boolean isOpened() { return this.hostBinding.isOpened(); } @Override public boolean isLoaded() { return this.hostBinding.isLoaded(); } @Override public boolean isStarted() { return this.hostBinding.isStarted(); } @Override public void open() { this.hostBinding.open(); } @Override public void load() { this.hostBinding.load(); } @Override public void start() { this.hostBinding.start(); } @Override public void stop() { this.hostBinding.stop(); } @Override public void unload() { this.hostBinding.unload(); } @Override public void close() { this.hostBinding.close(); } @Override public void willOpen() { this.hostContext.willOpen(); } @Override public void didOpen() { this.hostContext.didOpen(); } @Override public void willLoad() { this.hostContext.willLoad(); } @Override public void didLoad() { this.hostContext.didLoad(); } @Override public void willStart() { this.hostContext.willStart(); } @Override public void didStart() { this.hostContext.didStart(); } @Override public void didConnect() { this.hostContext.didConnect(); } @Override public void didDisconnect() { this.hostContext.didDisconnect(); } @Override public void willStop() { this.hostContext.willStop(); } @Override public void didStop() { this.hostContext.didStop(); } @Override public void willUnload() { this.hostContext.willUnload(); } @Override public void didUnload() { this.hostContext.didUnload(); } @Override public void willClose() { this.hostContext.willClose(); } @Override public void didClose() { this.hostBinding.didClose(); } @Override public void didFail(Throwable error) { this.hostBinding.didFail(error); } }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/HttpBinding.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.http.HttpRequest; import swim.http.HttpResponse; import swim.uri.Uri; public interface HttpBinding extends LinkBinding { @Override HttpBinding linkWrapper(); @Override HttpContext linkContext(); Uri requestUri(); HttpRequest<?> request(); HttpRequest<?> doRequest(); void writeResponse(HttpResponse<?> response); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/HttpContext.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.codec.Decoder; import swim.http.HttpRequest; import swim.http.HttpResponse; public interface HttpContext extends LinkContext { @Override HttpBinding linkWrapper(); Decoder<Object> decodeRequest(HttpRequest<?> request); void willRequest(HttpRequest<?> request); void didRequest(HttpRequest<Object> request); void doRespond(HttpRequest<Object> request); void willRespond(HttpResponse<?> response); void didRespond(HttpResponse<?> response); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/HttpProxy.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import java.net.InetSocketAddress; import java.security.Principal; import java.security.cert.Certificate; import java.util.Collection; import swim.api.auth.Identity; import swim.codec.Decoder; import swim.http.HttpRequest; import swim.http.HttpResponse; import swim.structure.Value; import swim.uri.Uri; public class HttpProxy implements HttpBinding, HttpContext { protected final HttpBinding linkBinding; protected HttpContext linkContext; public HttpProxy(HttpBinding linkBinding) { this.linkBinding = linkBinding; } @Override public final HttpBinding linkWrapper() { return this.linkBinding.linkWrapper(); } public final HttpBinding linkBinding() { return this.linkBinding; } @Override public final HttpContext linkContext() { return this.linkContext; } @Override public void setLinkContext(LinkContext linkContext) { this.linkContext = (HttpContext) linkContext; this.linkBinding.setLinkContext(this); } @Override public CellContext cellContext() { return this.linkBinding.cellContext(); } @Override public void setCellContext(CellContext cellContext) { this.linkBinding.setCellContext(cellContext); } @SuppressWarnings("unchecked") @Override public <T> T unwrapLink(Class<T> linkClass) { if (linkClass.isAssignableFrom(getClass())) { return (T) this; } else { return this.linkContext.unwrapLink(linkClass); } } @Override public Uri requestUri() { return this.linkBinding.requestUri(); } @Override public HttpRequest<?> request() { return this.linkBinding.request(); } @Override public Uri meshUri() { return this.linkBinding.meshUri(); } @Override public Uri hostUri() { return this.linkBinding.hostUri(); } @Override public Uri nodeUri() { return this.linkBinding.nodeUri(); } @Override public Uri laneUri() { return this.linkBinding.laneUri(); } @Override public Value linkKey() { return this.linkContext.linkKey(); } @Override public boolean isConnectedDown() { return this.linkBinding.isConnectedDown(); } @Override public boolean isRemoteDown() { return this.linkBinding.isRemoteDown(); } @Override public boolean isSecureDown() { return this.linkBinding.isSecureDown(); } @Override public String securityProtocolDown() { return this.linkBinding.securityProtocolDown(); } @Override public String cipherSuiteDown() { return this.linkBinding.cipherSuiteDown(); } @Override public InetSocketAddress localAddressDown() { return this.linkBinding.localAddressDown(); } @Override public Identity localIdentityDown() { return this.linkBinding.localIdentityDown(); } @Override public Principal localPrincipalDown() { return this.linkBinding.localPrincipalDown(); } @Override public Collection<Certificate> localCertificatesDown() { return this.linkBinding.localCertificatesDown(); } @Override public InetSocketAddress remoteAddressDown() { return this.linkBinding.remoteAddressDown(); } @Override public Identity remoteIdentityDown() { return this.linkBinding.remoteIdentityDown(); } @Override public Principal remotePrincipalDown() { return this.linkBinding.remotePrincipalDown(); } @Override public Collection<Certificate> remoteCertificatesDown() { return this.linkBinding.remoteCertificatesDown(); } @Override public boolean isConnectedUp() { return this.linkContext.isConnectedUp(); } @Override public boolean isRemoteUp() { return this.linkContext.isRemoteUp(); } @Override public boolean isSecureUp() { return this.linkContext.isSecureUp(); } @Override public String securityProtocolUp() { return this.linkContext.securityProtocolUp(); } @Override public String cipherSuiteUp() { return this.linkContext.cipherSuiteUp(); } @Override public InetSocketAddress localAddressUp() { return this.linkContext.localAddressUp(); } @Override public Identity localIdentityUp() { return this.linkContext.localIdentityUp(); } @Override public Principal localPrincipalUp() { return this.linkContext.localPrincipalUp(); } @Override public Collection<Certificate> localCertificatesUp() { return this.linkContext.localCertificatesUp(); } @Override public InetSocketAddress remoteAddressUp() { return this.linkContext.remoteAddressUp(); } @Override public Identity remoteIdentityUp() { return this.linkContext.remoteIdentityUp(); } @Override public Principal remotePrincipalUp() { return this.linkContext.remotePrincipalUp(); } @Override public Collection<Certificate> remoteCertificatesUp() { return this.linkContext.remoteCertificatesUp(); } @Override public HttpRequest<?> doRequest() { return this.linkBinding.doRequest(); } @Override public Decoder<Object> decodeRequest(HttpRequest<?> request) { return this.linkContext.decodeRequest(request); } @Override public void willRequest(HttpRequest<?> request) { this.linkContext.willRequest(request); } @Override public void didRequest(HttpRequest<Object> request) { this.linkContext.didRequest(request); } @Override public void doRespond(HttpRequest<Object> request) { this.linkContext.doRespond(request); } @Override public void writeResponse(HttpResponse<?> response) { this.linkBinding.writeResponse(response); } @Override public void willRespond(HttpResponse<?> response) { this.linkContext.willRespond(response); } @Override public void didRespond(HttpResponse<?> response) { this.linkContext.didRespond(response); } @Override public void openDown() { this.linkBinding.openDown(); } @Override public void closeDown() { this.linkBinding.closeDown(); } @Override public void closeUp() { this.linkContext.closeUp(); } @Override public void reopen() { this.linkBinding.reopen(); } @Override public void didOpenDown() { this.linkContext.didOpenDown(); } @Override public void didConnect() { this.linkBinding.didConnect(); } @Override public void didDisconnect() { this.linkBinding.didDisconnect(); } @Override public void didCloseDown() { this.linkContext.didCloseDown(); } @Override public void didCloseUp() { this.linkBinding.didCloseUp(); } @Override public void didFail(Throwable error) { this.linkBinding.didFail(error); } @Override public void traceDown(Object message) { this.linkBinding.traceDown(message); } @Override public void debugDown(Object message) { this.linkBinding.debugDown(message); } @Override public void infoDown(Object message) { this.linkBinding.infoDown(message); } @Override public void warnDown(Object message) { this.linkBinding.warnDown(message); } @Override public void errorDown(Object message) { this.linkBinding.errorDown(message); } @Override public void traceUp(Object message) { this.linkContext.traceUp(message); } @Override public void debugUp(Object message) { this.linkContext.debugUp(message); } @Override public void infoUp(Object message) { this.linkContext.infoUp(message); } @Override public void warnUp(Object message) { this.linkContext.warnUp(message); } @Override public void errorUp(Object message) { this.linkContext.errorUp(message); } }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/LaneBinding.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.api.Lane; import swim.api.agent.AgentContext; import swim.collections.FingerTrieSeq; import swim.concurrent.Schedule; import swim.concurrent.Stage; import swim.store.StoreBinding; import swim.structure.Value; import swim.uri.Uri; import swim.util.Log; import swim.warp.CommandMessage; public interface LaneBinding extends TierBinding, CellBinding, Log { NodeBinding node(); LaneBinding laneWrapper(); LaneContext laneContext(); void setLaneContext(LaneContext laneContext); <T> T unwrapLane(Class<T> laneClass); Uri meshUri(); Value partKey(); Uri hostUri(); Uri nodeUri(); Uri laneUri(); String laneType(); Schedule schedule(); Stage stage(); StoreBinding store(); Lane getLaneView(AgentContext agentContext); void openLaneView(Lane lane); void closeLaneView(Lane lane); FingerTrieSeq<LinkContext> uplinks(); LinkBinding getUplink(Value linkKey); void closeUplink(Value linkKey); void pushUpCommand(CommandMessage message); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/LaneContext.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.api.auth.Identity; import swim.structure.Value; import swim.uri.Uri; public interface LaneContext extends TierContext, CellContext { NodeBinding node(); LaneBinding laneWrapper(); <T> T unwrapLane(Class<T> laneClass); @Override Uri meshUri(); Value partKey(); Uri hostUri(); Uri nodeUri(); Uri laneUri(); Identity identity(); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/LaneDef.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.uri.Uri; import swim.uri.UriPattern; public interface LaneDef extends CellDef { Uri laneUri(); UriPattern lanePattern(); String laneType(); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/LaneModel.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import swim.api.Downlink; import swim.api.Lane; import swim.api.agent.AgentContext; import swim.api.policy.Policy; import swim.collections.FingerTrieSeq; import swim.concurrent.Schedule; import swim.concurrent.Stage; import swim.store.StoreBinding; import swim.structure.Value; import swim.uri.Uri; import swim.warp.CommandMessage; public abstract class LaneModel<View extends LaneView, U extends AbstractUplinkContext> extends AbstractTierBinding implements LaneBinding { protected LaneContext laneContext; protected volatile Object views; // View | LaneView[] protected volatile FingerTrieSeq<U> uplinks; public LaneModel() { this.uplinks = FingerTrieSeq.empty(); } @Override public final TierContext tierContext() { return this.laneContext; } @Override public final NodeBinding node() { return this.laneContext.node(); } @Override public final LaneBinding laneWrapper() { return this; } @Override public final LaneContext laneContext() { return this.laneContext; } @Override public void setLaneContext(LaneContext laneContext) { this.laneContext = laneContext; } @SuppressWarnings("unchecked") @Override public <T> T unwrapLane(Class<T> laneClass) { if (laneClass.isAssignableFrom(getClass())) { return (T) this; } else { return this.laneContext.unwrapLane(laneClass); } } protected abstract U createUplink(LinkBinding link); @Override public final Uri meshUri() { return this.laneContext.meshUri(); } @Override public final Value partKey() { return this.laneContext.partKey(); } @Override public final Uri hostUri() { return this.laneContext.hostUri(); } @Override public final Uri nodeUri() { return this.laneContext.nodeUri(); } @Override public final Uri laneUri() { return this.laneContext.laneUri(); } @Override public Policy policy() { return this.laneContext.policy(); } @Override public Schedule schedule() { return this.laneContext.schedule(); } @Override public Stage stage() { return this.laneContext.stage(); } @Override public StoreBinding store() { return this.laneContext.store(); } @Override public Lane getLaneView(AgentContext agentContext) { final Object views = this.views; LaneView view; if (views instanceof LaneView) { view = (LaneView) views; if (agentContext == view.agentContext()) { return view; } } else if (views instanceof LaneView[]) { final LaneView[] viewArray = (LaneView[]) views; for (int i = 0, n = viewArray.length; i < n; i += 1) { view = viewArray[i]; if (agentContext == view.agentContext()) { return view; } } } return null; } @SuppressWarnings("unchecked") @Override public void openLaneView(Lane view) { Object oldLaneViews; Object newLaneViews; do { oldLaneViews = this.views; if (oldLaneViews instanceof LaneView) { newLaneViews = new LaneView[]{(LaneView) oldLaneViews, (LaneView) view}; } else if (oldLaneViews instanceof LaneView[]) { final LaneView[] oldLaneViewArray = (LaneView[]) oldLaneViews; final int n = oldLaneViewArray.length; final LaneView[] newLaneViewArray = new LaneView[n + 1]; System.arraycopy(oldLaneViewArray, 0, newLaneViewArray, 0, n); newLaneViewArray[n] = (LaneView) view; newLaneViews = newLaneViewArray; } else { newLaneViews = (LaneView) view; } } while (!VIEWS.compareAndSet(this, oldLaneViews, newLaneViews)); didOpenLaneView((View) view); activate((View) view); } @SuppressWarnings("unchecked") @Override public void closeLaneView(Lane view) { Object oldLaneViews; Object newLaneViews; do { oldLaneViews = this.views; if (oldLaneViews instanceof LaneView) { if (oldLaneViews == view) { newLaneViews = null; continue; } } else if (oldLaneViews instanceof LaneView[]) { final LaneView[] oldLaneViewArray = (LaneView[]) oldLaneViews; final int n = oldLaneViewArray.length; if (n == 2) { if (oldLaneViewArray[0] == view) { newLaneViews = oldLaneViewArray[1]; continue; } else if (oldLaneViewArray[1] == view) { newLaneViews = oldLaneViewArray[0]; continue; } } else { // n > 2 final LaneView[] newLaneViewArray = new LaneView[n - 1]; int i = 0; while (i < n) { if (oldLaneViewArray[i] != view) { if (i < n - 1) { newLaneViewArray[i] = oldLaneViewArray[i]; } i += 1; } else { break; } } if (i < n) { System.arraycopy(oldLaneViewArray, i + 1, newLaneViewArray, i, n - (i + 1)); newLaneViews = newLaneViewArray; continue; } } } newLaneViews = oldLaneViews; break; } while (!VIEWS.compareAndSet(this, oldLaneViews, newLaneViews)); if (oldLaneViews != newLaneViews) { ((View) view).didClose(); didCloseLaneView((View) view); } if (newLaneViews == null) { close(); } } @SuppressWarnings("unchecked") @Override public FingerTrieSeq<LinkContext> uplinks() { return (FingerTrieSeq<LinkContext>) (FingerTrieSeq<?>) this.uplinks; } @SuppressWarnings("unchecked") @Override public LinkBinding getUplink(Value linkKey) { final FingerTrieSeq<U> uplinks = (FingerTrieSeq<U>) (FingerTrieSeq<?>) this.uplinks; for (int i = 0, n = uplinks.size(); i < n; i += 1) { final U uplink = uplinks.get(i); if (linkKey.equals(uplink.linkKey())) { return uplink.linkBinding(); } } return null; } @SuppressWarnings("unchecked") @Override public void openUplink(LinkBinding link) { FingerTrieSeq<U> oldUplinks; FingerTrieSeq<U> newUplinks; final U uplink = createUplink(link); if (uplink != null) { link.setLinkContext(uplink); do { oldUplinks = (FingerTrieSeq<U>) (FingerTrieSeq<?>) this.uplinks; newUplinks = oldUplinks.appended(uplink); } while (!UPLINKS.compareAndSet(this, oldUplinks, newUplinks)); didUplink(uplink); // TODO: onEnter } else { UplinkError.rejectUnsupported(link); } } @SuppressWarnings("unchecked") @Override public void closeUplink(Value linkKey) { FingerTrieSeq<U> oldUplinks; FingerTrieSeq<U> newUplinks; U linkContext; do { oldUplinks = (FingerTrieSeq<U>) (FingerTrieSeq<?>) this.uplinks; newUplinks = oldUplinks; linkContext = null; for (int i = 0, n = oldUplinks.size(); i < n; i += 1) { final U uplink = oldUplinks.get(i); if (linkKey.equals(uplink.linkKey())) { linkContext = uplink; newUplinks = oldUplinks.removed(i); break; } } } while (!UPLINKS.compareAndSet(this, oldUplinks, newUplinks)); if (linkContext != null) { linkContext.linkBinding().didCloseUp(); // TODO: onLeave } } @Override public abstract void pushUp(PushRequest pushRequest); @Override public abstract void pushUpCommand(CommandMessage message); protected abstract void didOpenLaneView(View view); protected void didCloseLaneView(View view) { // stub } protected void didUplink(U uplink) { // stub } @Override public LinkBinding bindDownlink(Downlink downlink) { return this.laneContext.bindDownlink(downlink); } @Override public void openDownlink(LinkBinding link) { this.laneContext.openDownlink(link); } @Override public void closeDownlink(LinkBinding link) { this.laneContext.closeDownlink(link); } @Override public void pushDown(PushRequest pushRequest) { this.laneContext.pushDown(pushRequest); } @Override public void trace(Object message) { this.laneContext.trace(message); } @Override public void debug(Object message) { this.laneContext.debug(message); } @Override public void info(Object message) { this.laneContext.info(message); } @Override public void warn(Object message) { this.laneContext.warn(message); } @Override public void error(Object message) { this.laneContext.error(message); } @Override protected void willOpen() { super.willOpen(); final Object views = this.views; if (views instanceof LaneView) { ((LaneView) views).open(); } else if (views instanceof LaneView[]) { final LaneView[] viewArray = (LaneView[]) views; for (int i = 0, n = viewArray.length; i < n; i += 1) { viewArray[i].open(); } } } @Override protected void willLoad() { super.willLoad(); final Object views = this.views; if (views instanceof LaneView) { ((LaneView) views).load(); } else if (views instanceof LaneView[]) { final LaneView[] viewArray = (LaneView[]) views; for (int i = 0, n = viewArray.length; i < n; i += 1) { viewArray[i].load(); } } } @Override protected void willStart() { super.willStart(); final Object views = this.views; if (views instanceof LaneView) { ((LaneView) views).start(); } else if (views instanceof LaneView[]) { final LaneView[] viewArray = (LaneView[]) views; for (int i = 0, n = viewArray.length; i < n; i += 1) { viewArray[i].start(); } } } @Override protected void willStop() { super.willStop(); final Object views = this.views; if (views instanceof LaneView) { ((LaneView) views).stop(); } else if (views instanceof LaneView[]) { final LaneView[] viewArray = (LaneView[]) views; for (int i = 0, n = viewArray.length; i < n; i += 1) { viewArray[i].stop(); } } } @Override protected void willUnload() { super.willUnload(); final Object views = this.views; if (views instanceof LaneView) { ((LaneView) views).unload(); } else if (views instanceof LaneView[]) { final LaneView[] viewArray = (LaneView[]) views; for (int i = 0, n = viewArray.length; i < n; i += 1) { viewArray[i].unload(); } } } @SuppressWarnings("unchecked") @Override protected void willClose() { super.willClose(); final FingerTrieSeq<U> uplinks = (FingerTrieSeq<U>) (FingerTrieSeq<?>) this.uplinks; for (int i = 0, n = uplinks.size(); i < n; i += 1) { uplinks.get(i).close(); } final Object views = this.views; if (views instanceof LaneView) { ((LaneView) views).close(); } else if (views instanceof LaneView[]) { final LaneView[] viewArray = (LaneView[]) views; for (int i = 0, n = viewArray.length; i < n; i += 1) { viewArray[i].close(); } } this.laneContext.close(); } @Override public void didClose() { } @Override public void didFail(Throwable error) { error.printStackTrace(); } @SuppressWarnings("unchecked") protected static final AtomicReferenceFieldUpdater<LaneModel<?, ?>, Object> VIEWS = AtomicReferenceFieldUpdater.newUpdater((Class<LaneModel<?, ?>>) (Class<?>) LaneModel.class, Object.class, "views"); @SuppressWarnings("unchecked") protected static final AtomicReferenceFieldUpdater<LaneModel<?, ?>, FingerTrieSeq<? extends LinkContext>> UPLINKS = AtomicReferenceFieldUpdater.newUpdater((Class<LaneModel<?, ?>>) (Class<?>) LaneModel.class, (Class<FingerTrieSeq<? extends LinkContext>>) (Class<?>) FingerTrieSeq.class, "uplinks"); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/LaneProxy.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.api.Downlink; import swim.api.Lane; import swim.api.agent.AgentContext; import swim.api.auth.Identity; import swim.api.policy.Policy; import swim.collections.FingerTrieSeq; import swim.concurrent.Schedule; import swim.concurrent.Stage; import swim.store.StoreBinding; import swim.structure.Value; import swim.uri.Uri; import swim.warp.CommandMessage; public class LaneProxy implements LaneBinding, LaneContext { protected final LaneBinding laneBinding; protected LaneContext laneContext; public LaneProxy(LaneBinding laneBinding) { this.laneBinding = laneBinding; } @Override public final TierContext tierContext() { return this; } @Override public final NodeBinding node() { return this.laneContext.node(); } @Override public final LaneBinding laneWrapper() { return this.laneBinding.laneWrapper(); } public final LaneBinding laneBinding() { return this.laneBinding; } @Override public final LaneContext laneContext() { return this.laneContext; } @Override public void setLaneContext(LaneContext laneContext) { this.laneContext = laneContext; this.laneBinding.setLaneContext(this); } @SuppressWarnings("unchecked") @Override public <T> T unwrapLane(Class<T> laneClass) { if (laneClass.isAssignableFrom(getClass())) { return (T) this; } else { return this.laneContext.unwrapLane(laneClass); } } @Override public Uri meshUri() { return this.laneContext.meshUri(); } @Override public Value partKey() { return this.laneContext.partKey(); } @Override public Uri hostUri() { return this.laneContext.hostUri(); } @Override public Uri nodeUri() { return this.laneContext.nodeUri(); } @Override public Uri laneUri() { return this.laneContext.laneUri(); } @Override public String laneType() { return this.laneBinding.laneType(); } @Override public Identity identity() { return this.laneContext.identity(); } @Override public Policy policy() { return this.laneContext.policy(); } @Override public Schedule schedule() { return this.laneContext.schedule(); } @Override public Stage stage() { return this.laneContext.stage(); } @Override public StoreBinding store() { return this.laneContext.store(); } @Override public Lane getLaneView(AgentContext agentContext) { return this.laneBinding.getLaneView(agentContext); } @Override public void openLaneView(Lane lane) { this.laneBinding.openLaneView(lane); } @Override public void closeLaneView(Lane lane) { this.laneBinding.closeLaneView(lane); } @Override public FingerTrieSeq<LinkContext> uplinks() { return this.laneBinding.uplinks(); } @Override public LinkBinding getUplink(Value linkKey) { return this.laneBinding.getUplink(linkKey); } @Override public void closeUplink(Value linkKey) { this.laneBinding.closeUplink(linkKey); } @Override public void pushUpCommand(CommandMessage message) { this.laneBinding.pushUpCommand(message); } @Override public LinkBinding bindDownlink(Downlink downlink) { return this.laneContext.bindDownlink(downlink); } @Override public void openDownlink(LinkBinding link) { this.laneContext.openDownlink(link); } @Override public void closeDownlink(LinkBinding link) { this.laneContext.closeDownlink(link); } @Override public void pushDown(PushRequest pushRequest) { this.laneContext.pushDown(pushRequest); } @Override public void openUplink(LinkBinding link) { this.laneBinding.openUplink(link); } @Override public void pushUp(PushRequest pushRequest) { this.laneBinding.pushUp(pushRequest); } @Override public void trace(Object message) { this.laneContext.trace(message); } @Override public void debug(Object message) { this.laneContext.debug(message); } @Override public void info(Object message) { this.laneContext.info(message); } @Override public void warn(Object message) { this.laneContext.warn(message); } @Override public void error(Object message) { this.laneContext.error(message); } @Override public boolean isClosed() { return this.laneBinding.isClosed(); } @Override public boolean isOpened() { return this.laneBinding.isOpened(); } @Override public boolean isLoaded() { return this.laneBinding.isLoaded(); } @Override public boolean isStarted() { return this.laneBinding.isStarted(); } @Override public void open() { this.laneBinding.open(); } @Override public void load() { this.laneBinding.load(); } @Override public void start() { this.laneBinding.start(); } @Override public void stop() { this.laneBinding.stop(); } @Override public void unload() { this.laneBinding.unload(); } @Override public void close() { this.laneBinding.close(); } @Override public void willOpen() { this.laneContext.willOpen(); } @Override public void didOpen() { this.laneContext.didOpen(); } @Override public void willLoad() { this.laneContext.willLoad(); } @Override public void didLoad() { this.laneContext.didLoad(); } @Override public void willStart() { this.laneContext.willStart(); } @Override public void didStart() { this.laneContext.didStart(); } @Override public void willStop() { this.laneContext.willStop(); } @Override public void didStop() { this.laneContext.didStop(); } @Override public void willUnload() { this.laneContext.willUnload(); } @Override public void didUnload() { this.laneContext.didUnload(); } @Override public void willClose() { this.laneContext.willClose(); } @Override public void didClose() { this.laneBinding.didClose(); } @Override public void didFail(Throwable error) { this.laneBinding.didFail(error); } }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/LaneRelay.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.concurrent.Conts; import swim.concurrent.Stage; public abstract class LaneRelay<Model extends LaneModel<View, ?>, View extends LaneView> implements Runnable { protected final Model model; protected final Object views; // View | View[] protected int viewIndex; protected final int viewCount; protected int phase; protected final int phaseCount; protected boolean preemptive; protected Stage stage; protected LaneRelay(Model model, int minPhase, int phaseCount, Stage stage) { this.model = model; this.views = model.views; if (this.views instanceof LaneView) { this.viewCount = 1; } else if (this.views instanceof LaneView[]) { this.viewCount = ((LaneView[]) views).length; } else { this.viewCount = 0; } this.phase = minPhase; this.phaseCount = phaseCount; this.preemptive = true; this.stage = stage; beginPhase(phase); } protected LaneRelay(Model model, int phaseCount) { this(model, 0, phaseCount, null); } protected LaneRelay(Model model) { this(model, 0, 1, null); } public boolean isDone() { return this.phase > this.phaseCount; } protected void beginPhase(int phase) { // stub } protected boolean runPhase(View view, int phase, boolean preemptive) { return true; } protected void endPhase(int phase) { // stub } protected void done() { // stub } void pass() { do { if (this.phase < this.phaseCount) { endPhase(this.phase); this.phase += 1; this.preemptive = true; if (this.phase < this.phaseCount) { beginPhase(this.phase); } else { endPhase(this.phase); this.phase += 1; done(); return; } } else { return; } } while (true); } void pass(View view) { do { if (this.viewIndex < this.viewCount) { try { if (!runPhase(view, this.phase, this.preemptive) && this.preemptive) { this.preemptive = false; if (this.stage == null) { this.stage = this.model.stage(); this.stage.execute(this); return; } else { continue; } } } catch (Throwable error) { if (Conts.isNonFatal(error)) { view.laneDidFail(error); } throw error; } this.viewIndex += 1; } else if (this.phase < this.phaseCount) { endPhase(this.phase); this.viewIndex = 0; this.phase += 1; this.preemptive = true; if (this.phase < this.phaseCount) { beginPhase(this.phase); } else { endPhase(this.phase); this.phase += 1; done(); return; } } else { return; } } while (true); } @SuppressWarnings("unchecked") void pass(LaneView[] views) { do { if (this.viewIndex < this.viewCount) { final View view = (View) views[this.viewIndex]; try { if (!runPhase(view, this.phase, this.preemptive) && this.preemptive) { this.preemptive = false; if (this.stage == null) { this.stage = this.model.stage(); this.stage.execute(this); return; } else { continue; } } } catch (Throwable error) { if (Conts.isNonFatal(error)) { view.laneDidFail(error); } throw error; } this.viewIndex += 1; } else if (this.phase < this.phaseCount) { endPhase(this.phase); this.viewIndex = 0; this.phase += 1; this.preemptive = true; if (this.phase < this.phaseCount) { beginPhase(this.phase); } else { endPhase(this.phase); this.phase += 1; done(); return; } } else { return; } } while (true); } @SuppressWarnings("unchecked") @Override public void run() { try { if (this.viewCount == 0) { pass(); } else if (this.viewCount == 1) { pass((View) views); } else if (this.viewCount > 1) { pass((LaneView[]) views); } } catch (Throwable error) { if (Conts.isNonFatal(error)) { this.model.didFail(error); } else { throw error; } } } }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/LaneView.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import swim.api.Downlink; import swim.api.Lane; import swim.api.agent.AgentContext; import swim.api.policy.Policy; import swim.concurrent.Schedule; import swim.concurrent.Stage; import swim.store.StoreBinding; import swim.uri.Uri; public abstract class LaneView extends AbstractTierBinding implements Lane { protected volatile Object observers; // Observer | Observer[] public LaneView(Object observers) { this.observers = observers; } @Override public TierContext tierContext() { return null; } public abstract AgentContext agentContext(); public abstract LaneBinding laneBinding(); public LaneContext laneContext() { return laneBinding().laneContext(); } public abstract LaneBinding createLaneBinding(); @SuppressWarnings("unchecked") public <T> T unwrapLane(Class<T> laneClass) { if (laneClass.isAssignableFrom(getClass())) { return (T) this; } else { return null; } } @Override public final Uri hostUri() { return laneBinding().hostUri(); } @Override public final Uri nodeUri() { return laneBinding().nodeUri(); } @Override public final Uri laneUri() { return laneBinding().laneUri(); } @Override public abstract void close(); @Override public LaneView observe(Object newObserver) { do { final Object oldObservers = this.observers; final Object newObservers; if (oldObservers == null) { newObservers = newObserver; } else if (!(oldObservers instanceof Object[])) { final Object[] newArray = new Object[2]; newArray[0] = oldObservers; newArray[1] = newObserver; newObservers = newArray; } else { final Object[] oldArray = (Object[]) oldObservers; final int oldCount = oldArray.length; final Object[] newArray = new Object[oldCount + 1]; System.arraycopy(oldArray, 0, newArray, 0, oldCount); newArray[oldCount] = newObserver; newObservers = newArray; } if (OBSERVERS.compareAndSet(this, oldObservers, newObservers)) { break; } } while (true); return this; } @Override public LaneView unobserve(Object oldObserver) { do { final Object oldObservers = this.observers; final Object newObservers; if (oldObservers == null) { break; } else if (!(oldObservers instanceof Object[])) { if (oldObservers == oldObserver) { // found as sole observer newObservers = null; } else { break; // not found } } else { final Object[] oldArray = (Object[]) oldObservers; final int oldCount = oldArray.length; if (oldCount == 2) { if (oldArray[0] == oldObserver) { // found at index 0 newObservers = oldArray[1]; } else if (oldArray[1] == oldObserver) { // found at index 1 newObservers = oldArray[0]; } else { break; // not found } } else { int i = 0; while (i < oldCount) { if (oldArray[i] == oldObserver) { // found at index i break; } i += 1; } if (i < oldCount) { final Object[] newArray = new Object[oldCount - 1]; System.arraycopy(oldArray, 0, newArray, 0, i); System.arraycopy(oldArray, i + 1, newArray, i, oldCount - 1 - i); newObservers = newArray; } else { break; // not found } } } if (OBSERVERS.compareAndSet(this, oldObservers, newObservers)) { break; } } while (true); return this; } public void laneDidFail(Throwable error) { // stub } @Override public Uri meshUri() { return laneContext().meshUri(); } @Override public Policy policy() { return laneContext().policy(); } @Override public Schedule schedule() { return laneContext().schedule(); } @Override public Stage stage() { return laneContext().stage(); } @Override public StoreBinding store() { return laneContext().store(); } @Override public LinkBinding bindDownlink(Downlink downlink) { return laneContext().bindDownlink(downlink); } @Override public void openDownlink(LinkBinding link) { laneContext().openDownlink(link); } @Override public void closeDownlink(LinkBinding link) { laneContext().closeDownlink(link); } @Override public void pushDown(PushRequest pushRequest) { laneContext().pushDown(pushRequest); } @Override public void trace(Object message) { laneBinding().trace(message); } @Override public void debug(Object message) { laneBinding().debug(message); } @Override public void info(Object message) { laneBinding().info(message); } @Override public void warn(Object message) { laneBinding().warn(message); } @Override public void error(Object message) { laneBinding().error(message); } static final AtomicReferenceFieldUpdater<LaneView, Object> OBSERVERS = AtomicReferenceFieldUpdater.newUpdater(LaneView.class, Object.class, "observers"); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/LinkBinding.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import java.net.InetSocketAddress; import java.security.Principal; import java.security.cert.Certificate; import java.util.Collection; import swim.api.auth.Identity; import swim.structure.Value; import swim.uri.Uri; public interface LinkBinding { LinkBinding linkWrapper(); LinkContext linkContext(); void setLinkContext(LinkContext linkContext); CellContext cellContext(); void setCellContext(CellContext cellContext); <T> T unwrapLink(Class<T> linkClass); Uri meshUri(); Uri hostUri(); Uri nodeUri(); Uri laneUri(); Value linkKey(); boolean isConnectedDown(); boolean isRemoteDown(); boolean isSecureDown(); String securityProtocolDown(); String cipherSuiteDown(); InetSocketAddress localAddressDown(); Identity localIdentityDown(); Principal localPrincipalDown(); Collection<Certificate> localCertificatesDown(); InetSocketAddress remoteAddressDown(); Identity remoteIdentityDown(); Principal remotePrincipalDown(); Collection<Certificate> remoteCertificatesDown(); void reopen(); void openDown(); void closeDown(); void didConnect(); void didDisconnect(); void didCloseUp(); void didFail(Throwable error); void traceDown(Object message); void debugDown(Object message); void infoDown(Object message); void warnDown(Object message); void errorDown(Object message); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/LinkContext.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import java.net.InetSocketAddress; import java.security.Principal; import java.security.cert.Certificate; import java.util.Collection; import swim.api.auth.Identity; import swim.structure.Value; public interface LinkContext { LinkBinding linkWrapper(); <T> T unwrapLink(Class<T> linkClass); Value linkKey(); boolean isConnectedUp(); boolean isRemoteUp(); boolean isSecureUp(); String securityProtocolUp(); String cipherSuiteUp(); InetSocketAddress localAddressUp(); Identity localIdentityUp(); Principal localPrincipalUp(); Collection<Certificate> localCertificatesUp(); InetSocketAddress remoteAddressUp(); Identity remoteIdentityUp(); Principal remotePrincipalUp(); Collection<Certificate> remoteCertificatesUp(); void closeUp(); void didOpenDown(); void didCloseDown(); void traceUp(Object message); void debugUp(Object message); void infoUp(Object message); void warnUp(Object message); void errorUp(Object message); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/LinkKeys.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import java.util.concurrent.atomic.AtomicLong; import swim.structure.Num; import swim.structure.Value; public final class LinkKeys { private LinkKeys() { // static } static final AtomicLong LINK_COUNT = new AtomicLong(0); public static Value generateLinkKey() { return Num.from(LINK_COUNT.incrementAndGet()); } }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/LogDef.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; public interface LogDef { }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/MeshBinding.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.collections.FingerTrieSeq; import swim.structure.Value; import swim.uri.Uri; public interface MeshBinding extends TierBinding, CellBinding, CellContext { EdgeBinding edge(); MeshBinding meshWrapper(); MeshContext meshContext(); void setMeshContext(MeshContext meshContext); <T> T unwrapMesh(Class<T> meshClass); Uri meshUri(); PartBinding gateway(); void setGateway(PartBinding gateway); PartBinding ourself(); void setOurself(PartBinding ourself); FingerTrieSeq<PartBinding> parts(); PartBinding getPart(Uri nodeUri); PartBinding getPart(Value partKey); PartBinding openPart(Uri nodeUri); PartBinding openGateway(); PartBinding addPart(Value partKey, PartBinding part); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/MeshContext.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.api.agent.Agent; import swim.api.agent.AgentDef; import swim.api.agent.AgentFactory; import swim.api.auth.Credentials; import swim.api.auth.Identity; import swim.api.policy.PolicyDirective; import swim.structure.Value; import swim.uri.Uri; public interface MeshContext extends TierContext, CellContext { EdgeBinding edge(); MeshBinding meshWrapper(); <T> T unwrapMesh(Class<T> meshClass); @Override Uri meshUri(); PartBinding createPart(Value partKey); PartBinding injectPart(Value partKey, PartBinding part); HostBinding createHost(Value partKey, Uri hostUri); HostBinding injectHost(Value partKey, Uri hostUri, HostBinding host); NodeBinding createNode(Value partKey, Uri hostUri, Uri nodeUri); NodeBinding injectNode(Value partKey, Uri hostUri, Uri nodeUri, NodeBinding node); LaneBinding createLane(Value partKey, Uri hostUri, Uri nodeUri, LaneDef laneDef); LaneBinding createLane(Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri); LaneBinding injectLane(Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri, LaneBinding lane); void openLanes(Value partKey, Uri hostUri, Uri nodeUri, NodeBinding node); AgentFactory<?> createAgentFactory(Value partKey, Uri hostUri, Uri nodeUri, AgentDef agentDef); <A extends Agent> AgentFactory<A> createAgentFactory(Value partKey, Uri hostUri, Uri nodeUri, Class<? extends A> agentClass); void openAgents(Value partKey, Uri hostUri, Uri nodeUri, NodeBinding node); PolicyDirective<Identity> authenticate(Credentials credentials); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/MeshDef.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import java.util.Collection; import swim.structure.Value; import swim.uri.Uri; public interface MeshDef extends CellDef { Uri meshUri(); Collection<? extends PartDef> partDefs(); PartDef getPartDef(Value partKey); Collection<? extends HostDef> hostDefs(); HostDef getHostDef(Uri hostUri); Collection<? extends NodeDef> nodeDefs(); NodeDef getNodeDef(Uri nodeUri); Collection<? extends LaneDef> laneDefs(); LaneDef getLaneDef(Uri laneUri); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/MeshProxy.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.api.Downlink; import swim.api.agent.Agent; import swim.api.agent.AgentDef; import swim.api.agent.AgentFactory; import swim.api.auth.Credentials; import swim.api.auth.Identity; import swim.api.policy.Policy; import swim.api.policy.PolicyDirective; import swim.collections.FingerTrieSeq; import swim.concurrent.Schedule; import swim.concurrent.Stage; import swim.store.StoreBinding; import swim.structure.Value; import swim.uri.Uri; public class MeshProxy implements MeshBinding, MeshContext { protected final MeshBinding meshBinding; protected MeshContext meshContext; public MeshProxy(MeshBinding meshBinding) { this.meshBinding = meshBinding; } @Override public final TierContext tierContext() { return this; } @Override public final EdgeBinding edge() { return this.meshContext.edge(); } @Override public final MeshBinding meshWrapper() { return this.meshBinding.meshWrapper(); } public final MeshBinding meshBinding() { return this.meshBinding; } @Override public final MeshContext meshContext() { return this.meshContext; } @Override public void setMeshContext(MeshContext meshContext) { this.meshContext = meshContext; this.meshBinding.setMeshContext(this); } @SuppressWarnings("unchecked") @Override public <T> T unwrapMesh(Class<T> meshClass) { if (meshClass.isAssignableFrom(getClass())) { return (T) this; } else { return this.meshContext.unwrapMesh(meshClass); } } @Override public Uri meshUri() { return this.meshContext.meshUri(); } @Override public Policy policy() { return this.meshContext.policy(); } @Override public Schedule schedule() { return this.meshContext.schedule(); } @Override public Stage stage() { return this.meshContext.stage(); } @Override public StoreBinding store() { return this.meshContext.store(); } @Override public PartBinding gateway() { return this.meshBinding.gateway(); } @Override public void setGateway(PartBinding gateway) { this.meshBinding.setGateway(gateway); } @Override public PartBinding ourself() { return this.meshBinding.ourself(); } @Override public void setOurself(PartBinding ourself) { this.meshBinding.setOurself(ourself); } @Override public FingerTrieSeq<PartBinding> parts() { return this.meshBinding.parts(); } @Override public PartBinding getPart(Uri nodeUri) { return this.meshBinding.getPart(nodeUri); } @Override public PartBinding getPart(Value partKey) { return this.meshBinding.getPart(partKey); } @Override public PartBinding openPart(Uri nodeUri) { return this.meshBinding.openPart(nodeUri); } @Override public PartBinding openGateway() { return this.meshBinding.openGateway(); } @Override public PartBinding addPart(Value partKey, PartBinding part) { return this.meshBinding.addPart(partKey, part); } @Override public PartBinding createPart(Value partKey) { return this.meshContext.createPart(partKey); } @Override public PartBinding injectPart(Value partKey, PartBinding part) { return this.meshContext.injectPart(partKey, part); } @Override public HostBinding createHost(Value partKey, Uri hostUri) { return this.meshContext.createHost(partKey, hostUri); } @Override public HostBinding injectHost(Value partKey, Uri hostUri, HostBinding host) { return this.meshContext.injectHost(partKey, hostUri, host); } @Override public NodeBinding createNode(Value partKey, Uri hostUri, Uri nodeUri) { return this.meshContext.createNode(partKey, hostUri, nodeUri); } @Override public NodeBinding injectNode(Value partKey, Uri hostUri, Uri nodeUri, NodeBinding node) { return this.meshContext.injectNode(partKey, hostUri, nodeUri, node); } @Override public LaneBinding createLane(Value partKey, Uri hostUri, Uri nodeUri, LaneDef laneDef) { return this.meshContext.createLane(partKey, hostUri, nodeUri, laneDef); } @Override public LaneBinding createLane(Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri) { return this.meshContext.createLane(partKey, hostUri, nodeUri, laneUri); } @Override public LaneBinding injectLane(Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri, LaneBinding lane) { return this.meshContext.injectLane(partKey, hostUri, nodeUri, laneUri, lane); } @Override public void openLanes(Value partKey, Uri hostUri, Uri nodeUri, NodeBinding node) { this.meshContext.openLanes(partKey, hostUri, nodeUri, node); } @Override public AgentFactory<?> createAgentFactory(Value partKey, Uri hostUri, Uri nodeUri, AgentDef agentDef) { return this.meshContext.createAgentFactory(partKey, hostUri, nodeUri, agentDef); } @Override public <A extends Agent> AgentFactory<A> createAgentFactory(Value partKey, Uri hostUri, Uri nodeUri, Class<? extends A> agentClass) { return this.meshContext.createAgentFactory(partKey, hostUri, nodeUri, agentClass); } @Override public void openAgents(Value partKey, Uri hostUri, Uri nodeUri, NodeBinding node) { this.meshContext.openAgents(partKey, hostUri, nodeUri, node); } @Override public PolicyDirective<Identity> authenticate(Credentials credentials) { return this.meshContext.authenticate(credentials); } @Override public LinkBinding bindDownlink(Downlink downlink) { return this.meshContext.bindDownlink(downlink); } @Override public void openDownlink(LinkBinding link) { this.meshContext.openDownlink(link); } @Override public void closeDownlink(LinkBinding link) { this.meshContext.closeDownlink(link); } @Override public void pushDown(PushRequest pushRequest) { this.meshContext.pushDown(pushRequest); } @Override public void openUplink(LinkBinding link) { this.meshBinding.openUplink(link); } @Override public void pushUp(PushRequest pushRequest) { this.meshBinding.pushUp(pushRequest); } @Override public void trace(Object message) { this.meshContext.trace(message); } @Override public void debug(Object message) { this.meshContext.debug(message); } @Override public void info(Object message) { this.meshContext.info(message); } @Override public void warn(Object message) { this.meshContext.warn(message); } @Override public void error(Object message) { this.meshContext.error(message); } @Override public boolean isClosed() { return this.meshBinding.isClosed(); } @Override public boolean isOpened() { return this.meshBinding.isOpened(); } @Override public boolean isLoaded() { return this.meshBinding.isLoaded(); } @Override public boolean isStarted() { return this.meshBinding.isStarted(); } @Override public void open() { this.meshBinding.open(); } @Override public void load() { this.meshBinding.load(); } @Override public void start() { this.meshBinding.start(); } @Override public void stop() { this.meshBinding.stop(); } @Override public void unload() { this.meshBinding.unload(); } @Override public void close() { this.meshBinding.close(); } @Override public void willOpen() { this.meshContext.willOpen(); } @Override public void didOpen() { this.meshContext.didOpen(); } @Override public void willLoad() { this.meshContext.willLoad(); } @Override public void didLoad() { this.meshContext.didLoad(); } @Override public void willStart() { this.meshContext.willStart(); } @Override public void didStart() { this.meshContext.didStart(); } @Override public void willStop() { this.meshContext.willStop(); } @Override public void didStop() { this.meshContext.didStop(); } @Override public void willUnload() { this.meshContext.willUnload(); } @Override public void didUnload() { this.meshContext.didUnload(); } @Override public void willClose() { this.meshContext.willClose(); } @Override public void didClose() { this.meshBinding.didClose(); } @Override public void didFail(Throwable error) { this.meshBinding.didFail(error); } }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/NodeBinding.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.api.agent.Agent; import swim.api.agent.AgentDef; import swim.api.agent.AgentFactory; import swim.collections.HashTrieMap; import swim.structure.Value; import swim.uri.Uri; public interface NodeBinding extends TierBinding, CellBinding { HostBinding host(); NodeBinding nodeWrapper(); NodeContext nodeContext(); void setNodeContext(NodeContext nodeContext); <T> T unwrapNode(Class<T> nodeClass); Uri meshUri(); Value partKey(); Uri hostUri(); Uri nodeUri(); long createdTime(); void openLanes(NodeBinding node); AgentFactory<?> createAgentFactory(AgentDef agentDef); <A extends Agent> AgentFactory<A> createAgentFactory(Class<? extends A> agentClass); void openAgents(NodeBinding node); HashTrieMap<Uri, LaneBinding> lanes(); LaneBinding getLane(Uri laneUri); LaneBinding openLane(Uri laneUri); LaneBinding openLane(Uri laneUri, LaneBinding lane); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/NodeContext.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.api.agent.Agent; import swim.api.agent.AgentDef; import swim.api.agent.AgentFactory; import swim.api.auth.Identity; import swim.structure.Value; import swim.uri.Uri; public interface NodeContext extends TierContext, CellContext { HostBinding host(); NodeBinding nodeWrapper(); <T> T unwrapNode(Class<T> nodeClass); @Override Uri meshUri(); Value partKey(); Uri hostUri(); Uri nodeUri(); long createdTime(); Identity identity(); LaneBinding createLane(LaneDef laneDef); LaneBinding createLane(Uri laneUri); LaneBinding injectLane(Uri laneUri, LaneBinding lane); void openLanes(NodeBinding node); AgentFactory<?> createAgentFactory(AgentDef agentDef); <A extends Agent> AgentFactory<A> createAgentFactory(Class<? extends A> agentClass); void openAgents(NodeBinding node); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/NodeDef.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import java.util.Collection; import swim.api.agent.AgentDef; import swim.collections.HashTrieMap; import swim.structure.Record; import swim.structure.Value; import swim.uri.Uri; import swim.uri.UriPattern; public interface NodeDef extends CellDef { Uri nodeUri(); UriPattern nodePattern(); default Value props(Uri nodeUri) { final Record props = Record.create(); final UriPattern pattern = nodePattern(); if (pattern != null) { final HashTrieMap<String, String> params = pattern.unapply(nodeUri); for (HashTrieMap.Entry<String, String> param : params) { props.slot(param.getKey(), param.getValue()); } } return props; } Collection<? extends AgentDef> agentDefs(); AgentDef getAgentDef(String agentName); Collection<? extends LaneDef> laneDefs(); LaneDef getLaneDef(Uri laneUri); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/NodeProxy.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.api.Downlink; import swim.api.agent.Agent; import swim.api.agent.AgentDef; import swim.api.agent.AgentFactory; import swim.api.auth.Identity; import swim.api.policy.Policy; import swim.collections.HashTrieMap; import swim.concurrent.Schedule; import swim.concurrent.Stage; import swim.store.StoreBinding; import swim.structure.Value; import swim.uri.Uri; public class NodeProxy implements NodeBinding, NodeContext { protected final NodeBinding nodeBinding; protected NodeContext nodeContext; public NodeProxy(NodeBinding nodeBinding) { this.nodeBinding = nodeBinding; } @Override public final TierContext tierContext() { return this; } @Override public final HostBinding host() { return this.nodeContext.host(); } @Override public final NodeBinding nodeWrapper() { return this.nodeBinding.nodeWrapper(); } public final NodeBinding nodeBinding() { return this.nodeBinding; } @Override public final NodeContext nodeContext() { return this.nodeContext; } @Override public void setNodeContext(NodeContext nodeContext) { this.nodeContext = nodeContext; this.nodeBinding.setNodeContext(this); } @SuppressWarnings("unchecked") @Override public <T> T unwrapNode(Class<T> nodeClass) { if (nodeClass.isAssignableFrom(getClass())) { return (T) this; } else { return this.nodeContext.unwrapNode(nodeClass); } } @Override public Uri meshUri() { return this.nodeContext.meshUri(); } @Override public Value partKey() { return this.nodeContext.partKey(); } @Override public Uri hostUri() { return this.nodeContext.hostUri(); } @Override public Uri nodeUri() { return this.nodeContext.nodeUri(); } @Override public long createdTime() { return this.nodeBinding.createdTime(); } @Override public Identity identity() { return this.nodeContext.identity(); } @Override public Policy policy() { return this.nodeContext.policy(); } @Override public Schedule schedule() { return this.nodeContext.schedule(); } @Override public Stage stage() { return this.nodeContext.stage(); } @Override public StoreBinding store() { return this.nodeContext.store(); } @Override public HashTrieMap<Uri, LaneBinding> lanes() { return this.nodeBinding.lanes(); } @Override public LaneBinding getLane(Uri laneUri) { return this.nodeBinding.getLane(laneUri); } @Override public LaneBinding openLane(Uri laneUri) { return this.nodeBinding.openLane(laneUri); } @Override public LaneBinding openLane(Uri laneUri, LaneBinding lane) { return this.nodeBinding.openLane(laneUri, lane); } @Override public LaneBinding createLane(LaneDef laneDef) { return this.nodeContext.createLane(laneDef); } @Override public LaneBinding createLane(Uri laneUri) { return this.nodeContext.createLane(laneUri); } @Override public LaneBinding injectLane(Uri laneUri, LaneBinding lane) { return this.nodeContext.injectLane(laneUri, lane); } @Override public void openLanes(NodeBinding node) { this.nodeContext.openLanes(node); } @Override public AgentFactory<?> createAgentFactory(AgentDef agentDef) { return this.nodeContext.createAgentFactory(agentDef); } @Override public <A extends Agent> AgentFactory<A> createAgentFactory(Class<? extends A> agentClass) { return this.nodeContext.createAgentFactory(agentClass); } @Override public void openAgents(NodeBinding node) { this.nodeContext.openAgents(node); } @Override public LinkBinding bindDownlink(Downlink downlink) { return this.nodeContext.bindDownlink(downlink); } @Override public void openDownlink(LinkBinding link) { this.nodeContext.openDownlink(link); } @Override public void closeDownlink(LinkBinding link) { this.nodeContext.closeDownlink(link); } @Override public void pushDown(PushRequest pushRequest) { this.nodeContext.pushDown(pushRequest); } @Override public void openUplink(LinkBinding link) { this.nodeBinding.openUplink(link); } @Override public void pushUp(PushRequest pushRequest) { this.nodeBinding.pushUp(pushRequest); } @Override public void trace(Object message) { this.nodeContext.trace(message); } @Override public void debug(Object message) { this.nodeContext.debug(message); } @Override public void info(Object message) { this.nodeContext.info(message); } @Override public void warn(Object message) { this.nodeContext.warn(message); } @Override public void error(Object message) { this.nodeContext.error(message); } @Override public boolean isClosed() { return this.nodeBinding.isClosed(); } @Override public boolean isOpened() { return this.nodeBinding.isOpened(); } @Override public boolean isLoaded() { return this.nodeBinding.isLoaded(); } @Override public boolean isStarted() { return this.nodeBinding.isStarted(); } @Override public void open() { this.nodeBinding.open(); } @Override public void load() { this.nodeBinding.load(); } @Override public void start() { this.nodeBinding.start(); } @Override public void stop() { this.nodeBinding.stop(); } @Override public void unload() { this.nodeBinding.unload(); } @Override public void close() { this.nodeBinding.close(); } @Override public void willOpen() { this.nodeContext.willOpen(); } @Override public void didOpen() { this.nodeContext.didOpen(); } @Override public void willLoad() { this.nodeContext.willLoad(); } @Override public void didLoad() { this.nodeContext.didLoad(); } @Override public void willStart() { this.nodeContext.willStart(); } @Override public void didStart() { this.nodeContext.didStart(); } @Override public void willStop() { this.nodeContext.willStop(); } @Override public void didStop() { this.nodeContext.didStop(); } @Override public void willUnload() { this.nodeContext.willUnload(); } @Override public void didUnload() { this.nodeContext.didUnload(); } @Override public void willClose() { this.nodeContext.willClose(); } @Override public void didClose() { this.nodeBinding.didClose(); } @Override public void didFail(Throwable error) { this.nodeBinding.didFail(error); } }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/PartBinding.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.collections.HashTrieMap; import swim.structure.Value; import swim.uri.Uri; public interface PartBinding extends TierBinding, CellBinding, CellContext { MeshBinding mesh(); PartBinding partWrapper(); PartContext partContext(); void setPartContext(PartContext partContext); <T> T unwrapPart(Class<T> partClass); Uri meshUri(); Value partKey(); PartPredicate predicate(); HostBinding master(); void setMaster(HostBinding master); HashTrieMap<Uri, HostBinding> hosts(); HostBinding getHost(Uri hostUri); HostBinding openHost(Uri hostUri); HostBinding openHost(Uri hostUri, HostBinding host); void reopenUplinks(); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/PartContext.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.api.agent.Agent; import swim.api.agent.AgentDef; import swim.api.agent.AgentFactory; import swim.api.auth.Credentials; import swim.api.auth.Identity; import swim.api.policy.PolicyDirective; import swim.structure.Value; import swim.uri.Uri; public interface PartContext extends TierContext, CellContext { MeshBinding mesh(); PartBinding partWrapper(); <T> T unwrapPart(Class<T> partClass); @Override Uri meshUri(); Value partKey(); HostBinding createHost(Uri hostUri); HostBinding injectHost(Uri hostUri, HostBinding host); NodeBinding createNode(Uri hostUri, Uri nodeUri); NodeBinding injectNode(Uri hostUri, Uri nodeUri, NodeBinding node); LaneBinding createLane(Uri hostUri, Uri nodeUri, LaneDef laneDef); LaneBinding createLane(Uri hostUri, Uri nodeUri, Uri laneUri); LaneBinding injectLane(Uri hostUri, Uri nodeUri, Uri laneUri, LaneBinding lane); void openLanes(Uri hostUri, Uri nodeUri, NodeBinding node); AgentFactory<?> createAgentFactory(Uri hostUri, Uri nodeUri, AgentDef agentDef); <A extends Agent> AgentFactory<A> createAgentFactory(Uri hostUri, Uri nodeUri, Class<? extends A> agentClass); void openAgents(Uri hostUri, Uri nodeUri, NodeBinding node); PolicyDirective<Identity> authenticate(Credentials credentials); void hostDidConnect(Uri hostUri); void hostDidDisconnect(Uri hostUri); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/PartDef.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import java.util.Collection; import swim.structure.Value; import swim.uri.Uri; public interface PartDef extends CellDef { Value partKey(); PartPredicate predicate(); boolean isGateway(); Collection<? extends HostDef> hostDefs(); HostDef getHostDef(Uri hostUri); Collection<? extends NodeDef> nodeDefs(); NodeDef getNodeDef(Uri nodeUri); Collection<? extends LaneDef> laneDefs(); LaneDef getLaneDef(Uri laneUri); }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/PartPredicate.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.structure.Form; import swim.structure.Item; import swim.structure.Kind; import swim.structure.Record; import swim.structure.Value; import swim.uri.Uri; import swim.uri.UriPattern; import swim.util.Murmur3; public abstract class PartPredicate { protected PartPredicate() { // stub } public abstract boolean test(Uri nodeUri, int nodeHash); public boolean test(Uri nodeUri) { return test(nodeUri, nodeUri.hashCode()); } public PartPredicate and(PartPredicate that) { return new AndPartPredicate(this, that); } public abstract Value toValue(); private static Form<PartPredicate> form; @Kind public static Form<PartPredicate> form() { if (form == null) { form = new PartPredicateForm(); } return form; } private static PartPredicate any; public static PartPredicate any() { if (any == null) { any = new AnyPartPredicate(); } return any; } public static PartPredicate and(PartPredicate... predicates) { return new AndPartPredicate(predicates); } public static PartPredicate node(UriPattern nodePattern) { return new NodePartPredicate(nodePattern); } public static PartPredicate node(String nodePattern) { return new NodePartPredicate(UriPattern.parse(nodePattern)); } public static PartPredicate hash(int lowerBound, int upperBound) { return new HashPartPredicate(lowerBound, upperBound); } public static PartPredicate fromValue(Value value) { final String tag = value.tag(); if ("node".equals(tag)) { return NodePartPredicate.fromValue(value); } else if ("hash".equals(tag)) { return HashPartPredicate.fromValue(value); } else { return null; } } } final class PartPredicateForm extends Form<PartPredicate> { @Override public Class<?> type() { return PartPredicate.class; } @Override public PartPredicate unit() { return PartPredicate.any(); } @Override public Value mold(PartPredicate predicate) { return predicate.toValue(); } @Override public PartPredicate cast(Item item) { return PartPredicate.fromValue(item.toValue()); } } final class AnyPartPredicate extends PartPredicate { @Override public boolean test(Uri nodeUri, int nodeHash) { return true; } @Override public PartPredicate and(PartPredicate that) { return that; } @Override public Value toValue() { return Value.absent(); } @Override public String toString() { return "PartPredicate" + '.' + "ANY"; } } final class AndPartPredicate extends PartPredicate { final PartPredicate[] predicates; AndPartPredicate(PartPredicate[] predicates) { this.predicates = predicates; } AndPartPredicate(PartPredicate f, PartPredicate g) { this(new PartPredicate[] {f, g}); } @Override public boolean test(Uri nodeUri, int nodeHash) { for (int i = 0, n = predicates.length; i < n; i += 1) { if (!predicates[i].test(nodeUri, nodeHash)) { return false; } } return true; } @Override public PartPredicate and(PartPredicate that) { final int n = predicates.length; final PartPredicate[] newPredicates = new PartPredicate[n + 1]; System.arraycopy(predicates, 0, newPredicates, 0, n); newPredicates[n] = that; return new AndPartPredicate(newPredicates); } @Override public Value toValue() { final int n = predicates.length; final Record record = Record.create(n); for (int i = 0; i < n; i += 1) { record.add(predicates[i].toValue()); } return record; } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof AndPartPredicate) { final AndPartPredicate that = (AndPartPredicate) other; final int n = predicates.length; if (n == that.predicates.length) { for (int i = 0; i < n; i += 1) { if (!predicates[i].equals(that.predicates[i])) { return false; } } return true; } } return false; } @Override public int hashCode() { int code = 0xFA5FC906; for (int i = 0, n = predicates.length; i < n; i += 1) { code = Murmur3.mix(code, predicates[i].hashCode()); } return Murmur3.mash(code); } @Override public String toString() { final StringBuilder s = new StringBuilder("PartPredicate").append('.').append("and").append('('); for (int i = 0, n = predicates.length; i < n; i += 1) { if (i > 0) { s.append(", "); } s.append(predicates[i]); } return s.append(')').toString(); } } final class NodePartPredicate extends PartPredicate { final UriPattern nodePattern; NodePartPredicate(UriPattern nodePattern) { this.nodePattern = nodePattern; } @Override public boolean test(Uri nodeUri, int nodeHash) { return nodePattern.matches(nodeUri); } @Override public Value toValue() { return Record.create(1).attr("node", nodePattern.toString()); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof NodePartPredicate) { final NodePartPredicate that = (NodePartPredicate) other; return nodePattern.equals(that.nodePattern); } else { return false; } } @Override public int hashCode() { return Murmur3.mash(Murmur3.mix(0x6C13D8A9, nodePattern.hashCode())); } @Override public String toString() { return "PartPredicate" + '.' + "node" + '(' + nodePattern + ')'; } public static NodePartPredicate fromValue(Value value) { final UriPattern nodePattern = UriPattern.parse(value.getAttr("node").stringValue()); return new NodePartPredicate(nodePattern); } } final class HashPartPredicate extends PartPredicate { final int lowerBound; final int upperBound; HashPartPredicate(int lowerBound, int upperBound) { this.lowerBound = lowerBound; this.upperBound = upperBound; } @Override public boolean test(Uri nodeUri, int nodeHash) { final long dlh = (long) (nodeHash - lowerBound) & 0xffffffffL; return 0L <= dlh && dlh < ((long) (upperBound - lowerBound) & 0xffffffffL); } @Override public Value toValue() { return Record.create(1).attr("hash", Record.create(2).item(lowerBound).item(upperBound)); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof HashPartPredicate) { final HashPartPredicate that = (HashPartPredicate) other; return lowerBound == that.lowerBound && upperBound == that.upperBound; } else { return false; } } private static int hashSeed; @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(HashPartPredicate.class); } return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed, lowerBound), upperBound)); } @Override public String toString() { return "PartPredicate" + '.' + "hash" + '(' + lowerBound + ", " + upperBound + ')'; } public static HashPartPredicate fromValue(Value value) { final Value header = value.getAttr("hash"); final int lowerBound = header.getItem(0).intValue(); final int upperBound = header.getItem(1).intValue(); return new HashPartPredicate(lowerBound, upperBound); } }
0
java-sources/ai/swim/swim-runtime/3.10.0/swim
java-sources/ai/swim/swim-runtime/3.10.0/swim/runtime/PartProxy.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.runtime; import swim.api.Downlink; import swim.api.agent.Agent; import swim.api.agent.AgentDef; import swim.api.agent.AgentFactory; import swim.api.auth.Credentials; import swim.api.auth.Identity; import swim.api.policy.Policy; import swim.api.policy.PolicyDirective; import swim.collections.HashTrieMap; import swim.concurrent.Schedule; import swim.concurrent.Stage; import swim.store.StoreBinding; import swim.structure.Value; import swim.uri.Uri; public class PartProxy implements PartBinding, PartContext { protected final PartBinding partBinding; protected PartContext partContext; public PartProxy(PartBinding partBinding) { this.partBinding = partBinding; } @Override public final TierContext tierContext() { return this; } @Override public final MeshBinding mesh() { return this.partContext.mesh(); } @Override public final PartBinding partWrapper() { return this.partBinding.partWrapper(); } public final PartBinding partBinding() { return this.partBinding; } @Override public final PartContext partContext() { return this.partContext; } @Override public void setPartContext(PartContext partContext) { this.partContext = partContext; this.partBinding.setPartContext(this); } @SuppressWarnings("unchecked") @Override public <T> T unwrapPart(Class<T> partClass) { if (partClass.isAssignableFrom(getClass())) { return (T) this; } else { return this.partContext.unwrapPart(partClass); } } @Override public Uri meshUri() { return this.partContext.meshUri(); } @Override public Policy policy() { return this.partContext.policy(); } @Override public Schedule schedule() { return this.partContext.schedule(); } @Override public Stage stage() { return this.partContext.stage(); } @Override public StoreBinding store() { return this.partContext.store(); } @Override public Value partKey() { return this.partContext.partKey(); } @Override public PartPredicate predicate() { return this.partBinding.predicate(); } @Override public HostBinding master() { return this.partBinding.master(); } @Override public void setMaster(HostBinding master) { this.partBinding.setMaster(master); } @Override public HashTrieMap<Uri, HostBinding> hosts() { return this.partBinding.hosts(); } @Override public HostBinding getHost(Uri hostUri) { return this.partBinding.getHost(hostUri); } @Override public HostBinding openHost(Uri hostUri) { return this.partBinding.openHost(hostUri); } @Override public HostBinding openHost(Uri hostUri, HostBinding host) { return this.partBinding.openHost(hostUri, host); } @Override public void hostDidConnect(Uri hostUri) { this.partContext.hostDidConnect(hostUri); } @Override public void hostDidDisconnect(Uri hostUri) { this.partContext.hostDidDisconnect(hostUri); } @Override public void reopenUplinks() { this.partBinding.reopenUplinks(); } @Override public HostBinding createHost(Uri hostUri) { return this.partContext.createHost(hostUri); } @Override public HostBinding injectHost(Uri hostUri, HostBinding host) { return this.partContext.injectHost(hostUri, host); } @Override public NodeBinding createNode(Uri hostUri, Uri nodeUri) { return this.partContext.createNode(hostUri, nodeUri); } @Override public NodeBinding injectNode(Uri hostUri, Uri nodeUri, NodeBinding node) { return this.partContext.injectNode(hostUri, nodeUri, node); } @Override public LaneBinding createLane(Uri hostUri, Uri nodeUri, LaneDef laneDef) { return this.partContext.createLane(hostUri, nodeUri, laneDef); } @Override public LaneBinding createLane(Uri hostUri, Uri nodeUri, Uri laneUri) { return this.partContext.createLane(hostUri, nodeUri, laneUri); } @Override public LaneBinding injectLane(Uri hostUri, Uri nodeUri, Uri laneUri, LaneBinding lane) { return this.partContext.injectLane(hostUri, nodeUri, laneUri, lane); } @Override public void openLanes(Uri hostUri, Uri nodeUri, NodeBinding node) { this.partContext.openLanes(hostUri, nodeUri, node); } @Override public AgentFactory<?> createAgentFactory(Uri hostUri, Uri nodeUri, AgentDef agentDef) { return this.partContext.createAgentFactory(hostUri, nodeUri, agentDef); } @Override public <A extends Agent> AgentFactory<A> createAgentFactory(Uri hostUri, Uri nodeUri, Class<? extends A> agentClass) { return this.partContext.createAgentFactory(hostUri, nodeUri, agentClass); } @Override public void openAgents(Uri hostUri, Uri nodeUri, NodeBinding node) { this.partContext.openAgents(hostUri, nodeUri, node); } @Override public PolicyDirective<Identity> authenticate(Credentials credentials) { return this.partContext.authenticate(credentials); } @Override public LinkBinding bindDownlink(Downlink downlink) { return this.partContext.bindDownlink(downlink); } @Override public void openDownlink(LinkBinding link) { this.partContext.openDownlink(link); } @Override public void closeDownlink(LinkBinding link) { this.partContext.closeDownlink(link); } @Override public void pushDown(PushRequest pushRequest) { this.partContext.pushDown(pushRequest); } @Override public void openUplink(LinkBinding link) { this.partBinding.openUplink(link); } @Override public void pushUp(PushRequest pushRequest) { this.partBinding.pushUp(pushRequest); } @Override public void trace(Object message) { this.partContext.trace(message); } @Override public void debug(Object message) { this.partContext.debug(message); } @Override public void info(Object message) { this.partContext.info(message); } @Override public void warn(Object message) { this.partContext.warn(message); } @Override public void error(Object message) { this.partContext.error(message); } @Override public boolean isClosed() { return this.partBinding.isClosed(); } @Override public boolean isOpened() { return this.partBinding.isOpened(); } @Override public boolean isLoaded() { return this.partBinding.isLoaded(); } @Override public boolean isStarted() { return this.partBinding.isStarted(); } @Override public void open() { this.partBinding.open(); } @Override public void load() { this.partBinding.load(); } @Override public void start() { this.partBinding.start(); } @Override public void stop() { this.partBinding.stop(); } @Override public void unload() { this.partBinding.unload(); } @Override public void close() { this.partBinding.close(); } @Override public void willOpen() { this.partContext.willOpen(); } @Override public void didOpen() { this.partContext.didOpen(); } @Override public void willLoad() { this.partContext.willLoad(); } @Override public void didLoad() { this.partContext.didLoad(); } @Override public void willStart() { this.partContext.willStart(); } @Override public void didStart() { this.partContext.didStart(); } @Override public void willStop() { this.partContext.willStop(); } @Override public void didStop() { this.partContext.didStop(); } @Override public void willUnload() { this.partContext.willUnload(); } @Override public void didUnload() { this.partContext.didUnload(); } @Override public void willClose() { this.partContext.willClose(); } @Override public void didClose() { this.partBinding.didClose(); } @Override public void didFail(Throwable error) { this.partBinding.didFail(error); } }