index int64 | repo_id string | file_path string | content string |
|---|---|---|---|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/HostObservableSpatialMap.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.dynamic.observable;
import swim.dynamic.Bridge;
import swim.dynamic.HostMethod;
import swim.dynamic.HostObjectType;
import swim.dynamic.JavaHostObjectType;
import swim.dynamic.java.lang.HostObject;
import swim.dynamic.observable.function.GuestDidClear;
import swim.dynamic.observable.function.GuestDidMoveShape;
import swim.dynamic.observable.function.GuestDidRemoveShape;
import swim.dynamic.observable.function.GuestDidUpdateShape;
import swim.dynamic.observable.function.GuestWillClear;
import swim.dynamic.observable.function.GuestWillMoveShape;
import swim.dynamic.observable.function.GuestWillRemoveShape;
import swim.dynamic.observable.function.GuestWillUpdateShape;
import swim.observable.ObservableSpatialMap;
public final class HostObservableSpatialMap {
private HostObservableSpatialMap() {
// static
}
public static final HostObjectType<ObservableSpatialMap<Object, Object, Object>> TYPE;
static {
final JavaHostObjectType<ObservableSpatialMap<Object, Object, Object>> type = new JavaHostObjectType<>(ObservableSpatialMap.class);
TYPE = type;
type.inheritType(HostObject.TYPE); // FIXME: replace with type.inheritType(HostSpatialMap.TYPE);
type.addMember(new HostObservableSpatialMapWillUpdate());
type.addMember(new HostObservableSpatialMapDidUpdate());
type.addMember(new HostObservableSpatialMapWillMove());
type.addMember(new HostObservableSpatialMapDidMove());
type.addMember(new HostObservableSpatialMapWillRemove());
type.addMember(new HostObservableSpatialMapDidRemove());
type.addMember(new HostObservableSpatialMapWillClear());
type.addMember(new HostObservableSpatialMapDidClear());
}
}
final class HostObservableSpatialMapWillUpdate implements HostMethod<ObservableSpatialMap<Object, Object, Object>> {
@Override
public String key() {
return "willUpdate";
}
@Override
public Object invoke(Bridge bridge, ObservableSpatialMap<Object, Object, Object> observable, Object... arguments) {
return observable.willUpdate(new GuestWillUpdateShape<Object, Object, Object>(bridge, arguments[0]));
}
}
final class HostObservableSpatialMapDidUpdate implements HostMethod<ObservableSpatialMap<Object, Object, Object>> {
@Override
public String key() {
return "didUpdate";
}
@Override
public Object invoke(Bridge bridge, ObservableSpatialMap<Object, Object, Object> observable, Object... arguments) {
return observable.didUpdate(new GuestDidUpdateShape<Object, Object, Object>(bridge, arguments[0]));
}
}
final class HostObservableSpatialMapWillMove implements HostMethod<ObservableSpatialMap<Object, Object, Object>> {
@Override
public String key() {
return "willMove";
}
@Override
public Object invoke(Bridge bridge, ObservableSpatialMap<Object, Object, Object> observable, Object... arguments) {
return observable.willMove(new GuestWillMoveShape<Object, Object, Object>(bridge, arguments[0]));
}
}
final class HostObservableSpatialMapDidMove implements HostMethod<ObservableSpatialMap<Object, Object, Object>> {
@Override
public String key() {
return "didMove";
}
@Override
public Object invoke(Bridge bridge, ObservableSpatialMap<Object, Object, Object> observable, Object... arguments) {
return observable.didMove(new GuestDidMoveShape<Object, Object, Object>(bridge, arguments[0]));
}
}
final class HostObservableSpatialMapWillRemove implements HostMethod<ObservableSpatialMap<Object, Object, Object>> {
@Override
public String key() {
return "willRemove";
}
@Override
public Object invoke(Bridge bridge, ObservableSpatialMap<Object, Object, Object> observable, Object... arguments) {
return observable.willRemove(new GuestWillRemoveShape<Object, Object>(bridge, arguments[0]));
}
}
final class HostObservableSpatialMapDidRemove implements HostMethod<ObservableSpatialMap<Object, Object, Object>> {
@Override
public String key() {
return "didRemove";
}
@Override
public Object invoke(Bridge bridge, ObservableSpatialMap<Object, Object, Object> observable, Object... arguments) {
return observable.didRemove(new GuestDidRemoveShape<Object, Object, Object>(bridge, arguments[0]));
}
}
final class HostObservableSpatialMapWillClear implements HostMethod<ObservableSpatialMap<Object, Object, Object>> {
@Override
public String key() {
return "willClear";
}
@Override
public Object invoke(Bridge bridge, ObservableSpatialMap<Object, Object, Object> observable, Object... arguments) {
return observable.willClear(new GuestWillClear(bridge, arguments[0]));
}
}
final class HostObservableSpatialMapDidClear implements HostMethod<ObservableSpatialMap<Object, Object, Object>> {
@Override
public String key() {
return "didClear";
}
@Override
public Object invoke(Bridge bridge, ObservableSpatialMap<Object, Object, Object> observable, Object... arguments) {
return observable.didClear(new GuestDidClear(bridge, arguments[0]));
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/HostObservableValue.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.dynamic.observable;
import swim.dynamic.Bridge;
import swim.dynamic.HostMethod;
import swim.dynamic.HostObjectType;
import swim.dynamic.JavaHostObjectType;
import swim.dynamic.java.lang.HostObject;
import swim.dynamic.observable.function.GuestDidSet;
import swim.dynamic.observable.function.GuestWillSet;
import swim.observable.ObservableValue;
public final class HostObservableValue {
private HostObservableValue() {
// static
}
public static final HostObjectType<ObservableValue<Object>> TYPE;
static {
final JavaHostObjectType<ObservableValue<Object>> type = new JavaHostObjectType<>(ObservableValue.class);
TYPE = type;
type.inheritType(HostObject.TYPE);
type.addMember(new HostObservableValueGet());
type.addMember(new HostObservableValueSet());
type.addMember(new HostObservableValueWillSet());
type.addMember(new HostObservableValueDidSet());
}
}
final class HostObservableValueGet implements HostMethod<ObservableValue<Object>> {
@Override
public String key() {
return "get";
}
@Override
public Object invoke(Bridge bridge, ObservableValue<Object> observable, Object... arguments) {
return observable.get();
}
}
final class HostObservableValueSet implements HostMethod<ObservableValue<Object>> {
@Override
public String key() {
return "set";
}
@Override
public Object invoke(Bridge bridge, ObservableValue<Object> observable, Object... arguments) {
return observable.set(arguments[0]);
}
}
final class HostObservableValueWillSet implements HostMethod<ObservableValue<Object>> {
@Override
public String key() {
return "willSet";
}
@Override
public Object invoke(Bridge bridge, ObservableValue<Object> observable, Object... arguments) {
return observable.willSet(new GuestWillSet<Object>(bridge, arguments[0]));
}
}
final class HostObservableValueDidSet implements HostMethod<ObservableValue<Object>> {
@Override
public String key() {
return "didSet";
}
@Override
public Object invoke(Bridge bridge, ObservableValue<Object> observable, Object... arguments) {
return observable.didSet(new GuestDidSet<Object>(bridge, arguments[0]));
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/SwimObservable.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.dynamic.observable;
import swim.dynamic.HostLibrary;
import swim.dynamic.HostPackage;
import swim.dynamic.JavaHostLibrary;
import swim.dynamic.JavaHostPackage;
public final class SwimObservable {
private SwimObservable() {
// static
}
public static final HostPackage PACKAGE;
public static final HostLibrary LIBRARY;
static {
final JavaHostPackage hostPkg = new JavaHostPackage("swim.observable");
PACKAGE = hostPkg;
hostPkg.addHostType(HostObservableList.TYPE);
hostPkg.addHostType(HostObservableMap.TYPE);
hostPkg.addHostType(HostObservableSortedMap.TYPE);
hostPkg.addHostType(HostObservableSpatialMap.TYPE);
hostPkg.addHostType(HostObservableValue.TYPE);
final JavaHostLibrary hostLib = new JavaHostLibrary("swim.observable");
LIBRARY = hostLib;
hostLib.addHostPackage(SwimObservable.PACKAGE);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/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.
/**
* swim.observable dynamic language bindings.
*/
package swim.dynamic.observable;
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestDidClear.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.DidClear;
public class GuestDidClear extends BridgeGuest implements DidClear {
public GuestDidClear(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void didClear() {
this.bridge.guestExecuteVoid(this.guest);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestDidDrop.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.DidDrop;
public class GuestDidDrop extends BridgeGuest implements DidDrop {
public GuestDidDrop(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void didDrop(int lower) {
this.bridge.guestExecuteVoid(this.guest, lower);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestDidMoveIndex.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.DidMoveIndex;
public class GuestDidMoveIndex<V> extends BridgeGuest implements DidMoveIndex<V> {
public GuestDidMoveIndex(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void didMove(int fromIndex, int toIndex, V value) {
this.bridge.guestExecuteVoid(this.guest, fromIndex, toIndex, value);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestDidMoveShape.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.DidMoveShape;
public class GuestDidMoveShape<K, S, V> extends BridgeGuest implements DidMoveShape<K, S, V> {
public GuestDidMoveShape(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void didMove(K key, S newShape, V newValue, S oldShape, V oldValue) {
this.bridge.guestExecuteVoid(this.guest, key, newShape, newValue, oldShape, oldValue);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestDidRemoveIndex.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.DidRemoveIndex;
public class GuestDidRemoveIndex<V> extends BridgeGuest implements DidRemoveIndex<V> {
public GuestDidRemoveIndex(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void didRemove(int index, V oldValue) {
this.bridge.guestExecuteVoid(this.guest, index, oldValue);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestDidRemoveKey.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.DidRemoveKey;
public class GuestDidRemoveKey<K, V> extends BridgeGuest implements DidRemoveKey<K, V> {
public GuestDidRemoveKey(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void didRemove(K key, V oldValue) {
this.bridge.guestExecuteVoid(this.guest, key, oldValue);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestDidRemoveShape.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.DidRemoveShape;
public class GuestDidRemoveShape<K, S, V> extends BridgeGuest implements DidRemoveShape<K, S, V> {
public GuestDidRemoveShape(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void didRemove(K key, S shape, V oldValue) {
this.bridge.guestExecuteVoid(this.guest, key, shape, oldValue);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestDidSet.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.DidSet;
public class GuestDidSet<V> extends BridgeGuest implements DidSet<V> {
public GuestDidSet(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void didSet(V newValue, V oldValue) {
this.bridge.guestExecuteVoid(this.guest, newValue, oldValue);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestDidTake.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.DidTake;
public class GuestDidTake extends BridgeGuest implements DidTake {
public GuestDidTake(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void didTake(int upper) {
this.bridge.guestExecuteVoid(this.guest, upper);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestDidUpdateIndex.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.DidUpdateIndex;
public class GuestDidUpdateIndex<V> extends BridgeGuest implements DidUpdateIndex<V> {
public GuestDidUpdateIndex(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void didUpdate(int index, V newValue, V oldValue) {
this.bridge.guestExecuteVoid(this.guest, index, newValue, oldValue);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestDidUpdateKey.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.DidUpdateKey;
public class GuestDidUpdateKey<K, V> extends BridgeGuest implements DidUpdateKey<K, V> {
public GuestDidUpdateKey(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void didUpdate(K key, V newValue, V oldValue) {
this.bridge.guestExecuteVoid(this.guest, key, newValue, oldValue);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestDidUpdateShape.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.DidUpdateShape;
public class GuestDidUpdateShape<K, S, V> extends BridgeGuest implements DidUpdateShape<K, S, V> {
public GuestDidUpdateShape(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void didUpdate(K key, S shape, V newValue, V oldValue) {
this.bridge.guestExecuteVoid(this.guest, key, shape, newValue, oldValue);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestWillClear.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.WillClear;
public class GuestWillClear extends BridgeGuest implements WillClear {
public GuestWillClear(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void willClear() {
this.bridge.guestExecuteVoid(this.guest);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestWillDrop.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.WillDrop;
public class GuestWillDrop extends BridgeGuest implements WillDrop {
public GuestWillDrop(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void willDrop(int lower) {
this.bridge.guestExecuteVoid(this.guest, lower);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestWillMoveIndex.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.WillMoveIndex;
public class GuestWillMoveIndex<V> extends BridgeGuest implements WillMoveIndex<V> {
public GuestWillMoveIndex(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void willMove(int fromIndex, int toIndex, V value) {
this.bridge.guestExecuteVoid(this.guest, fromIndex, toIndex, value);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestWillMoveShape.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.WillMoveShape;
public class GuestWillMoveShape<K, S, V> extends BridgeGuest implements WillMoveShape<K, S, V> {
public GuestWillMoveShape(Bridge bridge, Object guest) {
super(bridge, guest);
}
@SuppressWarnings("unchecked")
@Override
public V willMove(K key, S newShape, V newValue, S oldShape) {
return (V) this.bridge.guestExecute(this.guest, key, newShape, newValue, oldShape);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestWillRemoveIndex.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.WillRemoveIndex;
public class GuestWillRemoveIndex extends BridgeGuest implements WillRemoveIndex {
public GuestWillRemoveIndex(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void willRemove(int index) {
this.bridge.guestExecuteVoid(this.guest, index);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestWillRemoveKey.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.WillRemoveKey;
public class GuestWillRemoveKey<K> extends BridgeGuest implements WillRemoveKey<K> {
public GuestWillRemoveKey(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void willRemove(K key) {
this.bridge.guestExecuteVoid(this.guest, key);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestWillRemoveShape.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.WillRemoveShape;
public class GuestWillRemoveShape<K, S> extends BridgeGuest implements WillRemoveShape<K, S> {
public GuestWillRemoveShape(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void willRemove(K key, S shape) {
this.bridge.guestExecuteVoid(this.guest, key, shape);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestWillSet.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.WillSet;
public class GuestWillSet<V> extends BridgeGuest implements WillSet<V> {
public GuestWillSet(Bridge bridge, Object guest) {
super(bridge, guest);
}
@SuppressWarnings("unchecked")
@Override
public V willSet(V newValue) {
return (V) this.bridge.guestExecute(this.guest, newValue);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestWillTake.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.WillTake;
public class GuestWillTake extends BridgeGuest implements WillTake {
public GuestWillTake(Bridge bridge, Object guest) {
super(bridge, guest);
}
@Override
public void willTake(int upper) {
this.bridge.guestExecuteVoid(this.guest, upper);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestWillUpdateIndex.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.WillUpdateIndex;
public class GuestWillUpdateIndex<V> extends BridgeGuest implements WillUpdateIndex<V> {
public GuestWillUpdateIndex(Bridge bridge, Object guest) {
super(bridge, guest);
}
@SuppressWarnings("unchecked")
@Override
public V willUpdate(int index, V newValue) {
return (V) this.bridge.guestExecute(this.guest, index, newValue);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestWillUpdateKey.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.WillUpdateKey;
public class GuestWillUpdateKey<K, V> extends BridgeGuest implements WillUpdateKey<K, V> {
public GuestWillUpdateKey(Bridge bridge, Object guest) {
super(bridge, guest);
}
@SuppressWarnings("unchecked")
@Override
public V willUpdate(K key, V newValue) {
return (V) this.bridge.guestExecute(this.guest, key, newValue);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/GuestWillUpdateShape.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.dynamic.observable.function;
import swim.dynamic.Bridge;
import swim.dynamic.BridgeGuest;
import swim.observable.function.WillUpdateShape;
public class GuestWillUpdateShape<K, S, V> extends BridgeGuest implements WillUpdateShape<K, S, V> {
public GuestWillUpdateShape(Bridge bridge, Object guest) {
super(bridge, guest);
}
@SuppressWarnings("unchecked")
@Override
public V willUpdate(K key, S shape, V newValue) {
return (V) this.bridge.guestExecute(this.guest, key, shape, newValue);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable | java-sources/ai/swim/swim-dynamic-observable/3.10.0/swim/dynamic/observable/function/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.
/**
* swim.observable.function dynamic language bindings.
*/
package swim.dynamic.observable.function;
|
0 | java-sources/ai/swim/swim-dynamic-structure | java-sources/ai/swim/swim-dynamic-structure/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.structure dynamic language bindings.
*/
module swim.dynamic.structure {
requires transitive swim.structure;
requires transitive swim.dynamic;
requires transitive swim.dynamic.java;
exports swim.dynamic.structure;
}
|
0 | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic/structure/HostAbsent.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.dynamic.structure;
import swim.dynamic.HostObjectType;
import swim.dynamic.JavaHostClassType;
import swim.structure.Absent;
public final class HostAbsent {
private HostAbsent() {
// static
}
public static final HostObjectType<Absent> TYPE;
static {
final JavaHostClassType<Absent> type = new JavaHostClassType<>(Absent.class);
TYPE = type;
type.extendType(HostValue.TYPE);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic/structure/HostAttr.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.dynamic.structure;
import swim.dynamic.HostObjectType;
import swim.dynamic.JavaHostClassType;
import swim.structure.Attr;
public final class HostAttr {
private HostAttr() {
// static
}
public static final HostObjectType<Attr> TYPE;
static {
final JavaHostClassType<Attr> type = new JavaHostClassType<>(Attr.class);
TYPE = type;
type.extendType(HostField.TYPE);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic/structure/HostBool.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.dynamic.structure;
import swim.dynamic.HostObjectType;
import swim.dynamic.JavaHostClassType;
import swim.structure.Bool;
public final class HostBool {
private HostBool() {
// static
}
public static final HostObjectType<Bool> TYPE;
static {
final JavaHostClassType<Bool> type = new JavaHostClassType<>(Bool.class);
TYPE = type;
type.extendType(HostValue.TYPE);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic/structure/HostData.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.dynamic.structure;
import swim.dynamic.HostObjectType;
import swim.dynamic.JavaHostClassType;
import swim.structure.Data;
public final class HostData {
private HostData() {
// static
}
public static final HostObjectType<Data> TYPE;
static {
final JavaHostClassType<Data> type = new JavaHostClassType<>(Data.class);
TYPE = type;
type.extendType(HostValue.TYPE);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic/structure/HostExtant.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.dynamic.structure;
import swim.dynamic.HostObjectType;
import swim.dynamic.JavaHostClassType;
import swim.structure.Extant;
public final class HostExtant {
private HostExtant() {
// static
}
public static final HostObjectType<Extant> TYPE;
static {
final JavaHostClassType<Extant> type = new JavaHostClassType<>(Extant.class);
TYPE = type;
type.extendType(HostValue.TYPE);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic/structure/HostField.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.dynamic.structure;
import swim.dynamic.HostObjectType;
import swim.dynamic.JavaHostClassType;
import swim.structure.Field;
public final class HostField {
private HostField() {
// static
}
public static final HostObjectType<Field> TYPE;
static {
final JavaHostClassType<Field> type = new JavaHostClassType<>(Field.class);
TYPE = type;
type.extendType(HostItem.TYPE);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic/structure/HostItem.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.dynamic.structure;
import swim.dynamic.Bridge;
import swim.dynamic.HostMethod;
import swim.dynamic.HostObjectType;
import swim.dynamic.HostStaticMethod;
import swim.dynamic.JavaHostClassType;
import swim.dynamic.java.lang.HostObject;
import swim.structure.Item;
public final class HostItem {
private HostItem() {
// static
}
public static final HostObjectType<Item> TYPE;
static {
final JavaHostClassType<Item> type = new JavaHostClassType<>(Item.class);
TYPE = type;
type.extendType(HostObject.TYPE);
type.addMember(new HostItemIsDefined());
type.addMember(new HostItemIsDistinct());
type.addMember(new HostItemIsConstant());
type.addMember(new HostItemStringValue());
type.addMember(new HostItemNumberValue());
type.addMember(new HostItemBooleanValue());
type.addStaticMember(new HostItemAbsent());
type.addStaticMember(new HostItemExtant());
}
}
final class HostItemIsDefined implements HostMethod<Item> {
@Override
public String key() {
return "isDefined";
}
@Override
public Object invoke(Bridge bridge, Item item, Object... arguments) {
return item.isDefined();
}
}
final class HostItemIsDistinct implements HostMethod<Item> {
@Override
public String key() {
return "isDistinct";
}
@Override
public Object invoke(Bridge bridge, Item item, Object... arguments) {
return item.isDistinct();
}
}
final class HostItemIsConstant implements HostMethod<Item> {
@Override
public String key() {
return "isConstant";
}
@Override
public Object invoke(Bridge bridge, Item item, Object... arguments) {
return item.isConstant();
}
}
final class HostItemStringValue implements HostMethod<Item> {
@Override
public String key() {
return "stringValue";
}
@Override
public Object invoke(Bridge bridge, Item item, Object... arguments) {
if (arguments.length == 0) {
return item.stringValue();
} else {
return item.stringValue((String) arguments[0]);
}
}
}
final class HostItemNumberValue implements HostMethod<Item> {
@Override
public String key() {
return "numberValue";
}
@Override
public Object invoke(Bridge bridge, Item item, Object... arguments) {
if (arguments.length == 0) {
return item.numberValue();
} else {
return item.numberValue((Number) arguments[0]);
}
}
}
final class HostItemBooleanValue implements HostMethod<Item> {
@Override
public String key() {
return "booleanValue";
}
@Override
public Object invoke(Bridge bridge, Item item, Object... arguments) {
if (arguments.length == 0) {
return item.booleanValue();
} else {
return item.booleanValue((Boolean) arguments[0]);
}
}
}
final class HostItemAbsent implements HostStaticMethod {
@Override
public String key() {
return "absent";
}
@Override
public Object invoke(Bridge bridge, Object... arguments) {
return Item.absent();
}
}
final class HostItemExtant implements HostStaticMethod {
@Override
public String key() {
return "extant";
}
@Override
public Object invoke(Bridge bridge, Object... arguments) {
return Item.extant();
}
}
|
0 | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic/structure/HostNum.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.dynamic.structure;
import swim.dynamic.HostObjectType;
import swim.dynamic.JavaHostClassType;
import swim.structure.Num;
public final class HostNum {
private HostNum() {
// static
}
public static final HostObjectType<Num> TYPE;
static {
final JavaHostClassType<Num> type = new JavaHostClassType<>(Num.class);
TYPE = type;
type.extendType(HostValue.TYPE);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic/structure/HostRecord.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.dynamic.structure;
import swim.dynamic.HostObjectType;
import swim.dynamic.JavaHostClassType;
import swim.structure.Record;
public final class HostRecord {
private HostRecord() {
// static
}
public static final HostObjectType<Record> TYPE;
static {
final JavaHostClassType<Record> type = new JavaHostClassType<>(Record.class);
TYPE = type;
type.extendType(HostValue.TYPE);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic/structure/HostSlot.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.dynamic.structure;
import swim.dynamic.HostObjectType;
import swim.dynamic.JavaHostClassType;
import swim.structure.Slot;
public final class HostSlot {
private HostSlot() {
// static
}
public static final HostObjectType<Slot> TYPE;
static {
final JavaHostClassType<Slot> type = new JavaHostClassType<>(Slot.class);
TYPE = type;
type.extendType(HostField.TYPE);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic/structure/HostText.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.dynamic.structure;
import swim.dynamic.HostObjectType;
import swim.dynamic.JavaHostClassType;
import swim.structure.Text;
public final class HostText {
private HostText() {
// static
}
public static final HostObjectType<Text> TYPE;
static {
final JavaHostClassType<Text> type = new JavaHostClassType<>(Text.class);
TYPE = type;
type.extendType(HostValue.TYPE);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic/structure/HostValue.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.dynamic.structure;
import swim.dynamic.HostObjectType;
import swim.dynamic.JavaHostClassType;
import swim.structure.Value;
public final class HostValue {
private HostValue() {
// static
}
public static final HostObjectType<Value> TYPE;
static {
final JavaHostClassType<Value> type = new JavaHostClassType<>(Value.class);
TYPE = type;
type.extendType(HostItem.TYPE);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic/structure/SwimStructure.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.dynamic.structure;
import swim.dynamic.HostLibrary;
import swim.dynamic.HostPackage;
import swim.dynamic.JavaHostLibrary;
import swim.dynamic.JavaHostPackage;
public final class SwimStructure {
private SwimStructure() {
// static
}
public static final HostPackage PACKAGE;
public static final HostLibrary LIBRARY;
static {
final JavaHostPackage hostPkg = new JavaHostPackage("swim.structure");
PACKAGE = hostPkg;
hostPkg.addHostType(HostItem.TYPE);
hostPkg.addHostType(HostField.TYPE);
hostPkg.addHostType(HostAttr.TYPE);
hostPkg.addHostType(HostSlot.TYPE);
hostPkg.addHostType(HostValue.TYPE);
hostPkg.addHostType(HostRecord.TYPE);
hostPkg.addHostType(HostData.TYPE);
hostPkg.addHostType(HostText.TYPE);
hostPkg.addHostType(HostNum.TYPE);
hostPkg.addHostType(HostBool.TYPE);
hostPkg.addHostType(HostExtant.TYPE);
hostPkg.addHostType(HostAbsent.TYPE);
final JavaHostLibrary hostLib = new JavaHostLibrary("swim.structure");
LIBRARY = hostLib;
hostLib.addHostPackage(SwimStructure.PACKAGE);
}
}
|
0 | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic | java-sources/ai/swim/swim-dynamic-structure/3.10.0/swim/dynamic/structure/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.
/**
* swim.structure dynamic language bindings.
*/
package swim.dynamic.structure;
|
0 | java-sources/ai/swim/swim-fabric | java-sources/ai/swim/swim-fabric/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 fabric runtime.
*/
module swim.fabric {
requires transitive swim.runtime;
requires transitive swim.kernel;
exports swim.fabric;
provides swim.kernel.Kernel with swim.fabric.FabricKernel;
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/Fabric.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.fabric;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import swim.api.Downlink;
import swim.api.SwimContext;
import swim.api.agent.Agent;
import swim.api.agent.AgentDef;
import swim.api.agent.AgentFactory;
import swim.api.agent.AgentRoute;
import swim.api.agent.AgentRouteContext;
import swim.api.auth.Authenticator;
import swim.api.auth.AuthenticatorContext;
import swim.api.auth.Credentials;
import swim.api.auth.Identity;
import swim.api.plane.Plane;
import swim.api.plane.PlaneContext;
import swim.api.plane.PlaneFactory;
import swim.api.policy.PlanePolicy;
import swim.api.policy.Policy;
import swim.api.policy.PolicyDirective;
import swim.api.space.Space;
import swim.collections.HashTrieMap;
import swim.concurrent.MainStage;
import swim.concurrent.Schedule;
import swim.concurrent.Stage;
import swim.concurrent.StageDef;
import swim.kernel.KernelContext;
import swim.runtime.AbstractTierBinding;
import swim.runtime.EdgeBinding;
import swim.runtime.EdgeContext;
import swim.runtime.HostBinding;
import swim.runtime.HostDef;
import swim.runtime.LaneBinding;
import swim.runtime.LaneDef;
import swim.runtime.LinkBinding;
import swim.runtime.LogDef;
import swim.runtime.MeshBinding;
import swim.runtime.MeshDef;
import swim.runtime.NodeBinding;
import swim.runtime.NodeDef;
import swim.runtime.PartBinding;
import swim.runtime.PartDef;
import swim.runtime.PolicyDef;
import swim.runtime.PushRequest;
import swim.runtime.TierContext;
import swim.runtime.agent.AgentModel;
import swim.store.StoreBinding;
import swim.store.StoreDef;
import swim.structure.Value;
import swim.uri.Uri;
import swim.uri.UriMapper;
import swim.uri.UriPattern;
import swim.util.Log;
public class Fabric extends AbstractTierBinding implements EdgeContext, PlaneContext, Space {
final String spaceName;
final FabricDef fabricDef;
final KernelContext kernel;
final EdgeBinding edge;
Log log;
PlanePolicy policy;
Stage stage;
StoreBinding store;
volatile HashTrieMap<String, Plane> planes;
volatile HashTrieMap<String, AgentRoute<?>> agentRoutes;
volatile UriMapper<AgentFactory<?>> agentFactories;
volatile HashTrieMap<String, Authenticator> authenticators;
public Fabric(String spaceName, FabricDef fabricDef, KernelContext kernel) {
this.spaceName = spaceName;
this.fabricDef = fabricDef;
this.kernel = kernel;
EdgeBinding edge = createEdge();
edge = injectEdge(edge);
edge.setEdgeContext(this);
edge = edge.edgeWrapper();
this.edge = edge;
this.planes = HashTrieMap.empty();
this.agentRoutes = HashTrieMap.empty();
this.agentFactories = UriMapper.empty();
this.authenticators = HashTrieMap.empty();
openEdge(this.edge);
}
public final String spaceName() {
return this.spaceName;
}
public final FabricDef fabricDef() {
return this.fabricDef;
}
@Override
public final TierContext tierContext() {
return null;
}
@Override
public final EdgeBinding edgeWrapper() {
return this.edge.edgeWrapper();
}
@SuppressWarnings("unchecked")
@Override
public <T> T unwrapEdge(Class<T> edgeClass) {
if (edgeClass.isAssignableFrom(getClass())) {
return (T) this;
} else {
return null;
}
}
@Override
public final Uri meshUri() {
return Uri.empty();
}
@Override
public final PlanePolicy policy() {
return this.policy;
}
@Override
public void setPolicy(PlanePolicy policy) {
this.policy = policy;
}
@Override
public Schedule schedule() {
return this.stage;
}
@Override
public final Stage stage() {
return this.stage;
}
@Override
public final StoreBinding store() {
return this.store;
}
public final KernelContext kernel() {
return this.kernel;
}
public final EdgeBinding edge() {
return this.edge;
}
@Override
public Authenticator getAuthenticator(String authenticatorName) {
return this.authenticators.get(authenticatorName);
}
@Override
public void addAuthenticator(String authenticatorName, Authenticator authenticator) {
final AuthenticatorContext authenticatorContext = new FabricAuthenticator(authenticatorName, this.kernel);
authenticator.setAuthenticatorContext(authenticatorContext);
HashTrieMap<String, Authenticator> oldAuthenticators;
HashTrieMap<String, Authenticator> newAuthenticators;
do {
oldAuthenticators = this.authenticators;
newAuthenticators = oldAuthenticators.updated(authenticatorName, authenticator);
} while (!AUTHENTICATORS.compareAndSet(this, oldAuthenticators, newAuthenticators));
}
@Override
public Collection<? extends Plane> planes() {
return this.planes.values();
}
@Override
public Plane getPlane(String planeName) {
return this.planes.get(planeName);
}
@SuppressWarnings("unchecked")
@Override
public <P extends Plane> P getPlane(Class<? extends P> planeClass) {
for (Plane plane : this.planes.values()) {
if (planeClass.isAssignableFrom(plane.getClass())) {
return (P) plane;
}
}
return null;
}
@SuppressWarnings("unchecked")
@Override
public <P extends Plane> P openPlane(String planeName, PlaneFactory<P> planeFactory) {
P plane = null;
do {
final HashTrieMap<String, Plane> oldPlanes = this.planes;
final Plane oldPlane = oldPlanes.get(planeName);
if (oldPlane == null) {
if (plane == null) {
plane = createPlane(planeFactory);
plane = (P) this.kernel.injectPlane(plane);
}
final HashTrieMap<String, Plane> newPlanes = oldPlanes.updated(planeName, plane);
if (PLANES.compareAndSet(this, oldPlanes, newPlanes)) {
break;
}
} else {
plane = (P) oldPlane;
break;
}
} while (true);
return plane;
}
@SuppressWarnings("unchecked")
@Override
public <P extends Plane> P openPlane(String planeName, Class<? extends P> planeClass) {
Plane plane = getPlane(planeName);
if (plane == null) {
final PlaneFactory<P> planeFactory = this.kernel.createPlaneFactory(planeClass);
if (planeFactory != null) {
plane = openPlane(planeName, planeFactory);
}
}
return (P) plane;
}
protected <P extends Plane> P createPlane(PlaneFactory<P> planeFactory) {
try {
SwimContext.setPlaneContext(this);
return planeFactory.createPlane(this);
} finally {
SwimContext.clear();
}
}
@SuppressWarnings("unchecked")
@Override
public <A extends Agent> AgentRoute<A> getAgentRoute(String routeName) {
return (AgentRoute<A>) this.agentRoutes.get(routeName);
}
@Override
public <A extends Agent> AgentRoute<A> createAgentRoute(Class<? extends A> agentClass) {
return this.kernel.createAgentRoute(this.spaceName, agentClass);
}
@Override
public void addAgentRoute(String routeName, UriPattern pattern, AgentRoute<?> agentRoute) {
final AgentRouteContext agentRouteContext = new FabricAgentRoute(routeName, pattern);
agentRoute.setAgentRouteContext(agentRouteContext);
HashTrieMap<String, AgentRoute<?>> oldAgentRoutes;
HashTrieMap<String, AgentRoute<?>> newAgentRoutes;
do {
oldAgentRoutes = this.agentRoutes;
newAgentRoutes = oldAgentRoutes.updated(routeName, agentRoute);
} while (oldAgentRoutes != newAgentRoutes && !AGENT_ROUTES.compareAndSet(this, oldAgentRoutes, newAgentRoutes));
UriMapper<AgentFactory<?>> oldAgentFactories;
UriMapper<AgentFactory<?>> newAgentFactories;
do {
oldAgentFactories = this.agentFactories;
newAgentFactories = oldAgentFactories.updated(pattern, agentRoute);
} while (oldAgentFactories != newAgentFactories && !AGENT_FACTORIES.compareAndSet(this, oldAgentFactories, newAgentFactories));
}
@Override
public void addAgentRoute(String routeName, String pattern, AgentRoute<?> agentRoute) {
addAgentRoute(routeName, UriPattern.parse(pattern), agentRoute);
}
@Override
public void removeAgentRoute(String routeName) {
HashTrieMap<String, AgentRoute<?>> oldAgentRoutes;
HashTrieMap<String, AgentRoute<?>> newAgentRoutes;
do {
oldAgentRoutes = this.agentRoutes;
newAgentRoutes = oldAgentRoutes.removed(routeName);
} while (oldAgentRoutes != newAgentRoutes && !AGENT_ROUTES.compareAndSet(this, oldAgentRoutes, newAgentRoutes));
final AgentRoute<?> agentRoute = oldAgentRoutes.get(routeName);
if (agentRoute != null) {
UriMapper<AgentFactory<?>> oldAgentFactories;
UriMapper<AgentFactory<?>> newAgentFactories;
do {
oldAgentFactories = this.agentFactories;
newAgentFactories = oldAgentFactories.removed(agentRoute.pattern());
} while (oldAgentFactories != newAgentFactories && !AGENT_FACTORIES.compareAndSet(this, oldAgentFactories, newAgentFactories));
}
}
@Override
public AgentFactory<?> getAgentFactory(Uri nodeUri) {
return this.agentFactories.get(nodeUri);
}
@Override
public AgentFactory<?> createAgentFactory(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, AgentDef agentDef) {
return this.kernel.createAgentFactory(this.spaceName, 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.kernel.createAgentFactory(this.spaceName, meshUri, partKey, hostUri, nodeUri, agentClass);
}
@Override
public void openAgents(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, NodeBinding node) {
this.kernel.openAgents(this.spaceName, meshUri, partKey, hostUri, nodeUri, node);
if (!meshUri.isDefined()) {
final NodeDef nodeDef = this.fabricDef.getNodeDef(nodeUri);
if (nodeDef != null && node instanceof AgentModel) {
final AgentModel agentModel = (AgentModel) node;
for (AgentDef agentDef : nodeDef.agentDefs()) {
final AgentFactory<?> agentFactory = createAgentFactory(meshUri, partKey, hostUri, nodeUri, agentDef);
if (agentDef != null) {
Value props = agentDef.props();
if (!props.isDefined()) {
props = agentModel.props();
}
agentModel.addAgentView(agentModel.createAgent(agentFactory, props));
}
}
}
final AgentFactory<?> agentFactory = this.agentFactories.get(nodeUri);
if (agentFactory != null && node instanceof AgentModel) {
final AgentModel agentModel = (AgentModel) node;
agentModel.addAgentView(agentModel.createAgent(agentFactory, agentModel.props()));
}
}
}
public Log createLog(LogDef logDef) {
return this.kernel.createLog(logDef);
}
public Log injectLog(Log log) {
return this.kernel.injectLog(log);
}
protected Log openLog() {
Log log;
if (this.fabricDef.logDef != null) {
log = createLog(this.fabricDef.logDef);
} else {
log = openEdgeLog();
}
if (log != null) {
log = injectLog(log);
}
return log;
}
protected void closeLog() {
this.log = null;
}
public Policy createPolicy(PolicyDef policyDef) {
return this.kernel.createPolicy(policyDef);
}
public Policy injectPolicy(Policy policy) {
return this.kernel.injectPolicy(policy);
}
protected PlanePolicy openPolicy() {
Policy policy;
if (this.fabricDef.policyDef != null) {
policy = createPolicy(this.fabricDef.policyDef);
} else {
policy = openEdgePolicy();
}
if (policy != null) {
policy = injectPolicy(policy);
}
return (PlanePolicy) policy;
}
protected void closePolicy() {
this.policy = null;
}
public Stage createStage(StageDef stageDef) {
return this.kernel.createStage(stageDef);
}
public Stage injectStage(Stage stage) {
return this.kernel.injectStage(stage);
}
protected Stage openStage() {
Stage stage;
if (this.fabricDef.stageDef != null) {
stage = createStage(this.fabricDef.stageDef);
} else {
stage = openEdgeStage();
}
if (stage != null) {
stage = injectStage(stage);
}
return stage;
}
protected void closeStage() {
final Stage stage = this.stage;
if (stage instanceof MainStage) {
((MainStage) stage).stop();
}
this.stage = null;
}
public StoreBinding createStore(StoreDef storeDef) {
return this.kernel.createStore(storeDef, null);
}
public StoreBinding injectStore(StoreBinding store) {
return this.kernel.injectStore(store);
}
protected StoreBinding openStore() {
StoreBinding store = null;
if (this.fabricDef.storeDef != null) {
store = createStore(this.fabricDef.storeDef);
} else {
store = openEdgeStore();
}
if (store != null) {
store = injectStore(store);
}
return store;
}
protected void closeStore() {
final StoreBinding store = this.store;
if (store != null) {
store.close();
}
this.store = null;
}
protected EdgeBinding createEdge() {
EdgeBinding edge = this.kernel.createEdge(this.spaceName);
if (edge != null) {
edge = this.kernel.injectEdge(this.spaceName, edge);
}
return edge;
}
protected void openEdge(EdgeBinding edge) {
for (MeshDef meshDef : this.fabricDef.meshDefs()) {
createMesh(edge, meshDef);
}
if (edge.network() == null) {
final MeshBinding network = edge.openMesh(Uri.empty());
edge.setNetwork(network);
final PartBinding gateway = network.openGateway();
final HostBinding localHost = gateway.openHost(Uri.empty());
gateway.setMaster(localHost);
}
}
protected MeshBinding createMesh(EdgeBinding edge, MeshDef meshDef) {
final Uri meshUri = meshDef.meshUri();
MeshBinding mesh = this.kernel.createMesh(this.spaceName, meshDef);
if (mesh != null) {
mesh = edge.openMesh(meshUri, mesh);
if (mesh != null) {
if (!meshUri.isDefined()) {
edge.setNetwork(mesh);
}
for (PartDef partDef : meshDef.partDefs()) {
createPart(edge, mesh, partDef);
}
}
}
return mesh;
}
protected PartBinding createPart(EdgeBinding edge, MeshBinding mesh, PartDef partDef) {
final Uri meshUri = mesh.meshUri();
final Value partKey = partDef.partKey();
PartBinding part = this.kernel.createPart(this.spaceName, meshUri, partDef);
if (part != null) {
part = mesh.addPart(partKey, part);
if (part != null) {
if (partDef.isGateway()) {
mesh.setGateway(part);
}
for (HostDef hostDef : partDef.hostDefs()) {
createHost(edge, mesh, part, hostDef);
}
}
}
return part;
}
protected HostBinding createHost(EdgeBinding edge, MeshBinding mesh, PartBinding part, HostDef hostDef) {
final Uri meshUri = mesh.meshUri();
final Value partKey = part.partKey();
final Uri hostUri = hostDef.hostUri();
HostBinding host = null;
if (hostUri != null) {
host = this.kernel.createHost(this.spaceName, meshUri, partKey, hostDef);
if (host != null) {
host = part.openHost(hostUri, host);
if (host != null) {
host.setReplica(hostDef.isReplica());
if (hostDef.isPrimary()) {
host.setPrimary(true);
part.setMaster(host);
host.didBecomeMaster();
} else if (hostDef.isReplica()) {
host.didBecomeSlave();
}
for (NodeDef nodeDef : hostDef.nodeDefs()) {
createNode(edge, mesh, part, host, nodeDef);
}
}
}
}
return host;
}
protected NodeBinding createNode(EdgeBinding edge, MeshBinding mesh, PartBinding part,
HostBinding host, NodeDef nodeDef) {
final Uri meshUri = mesh.meshUri();
final Value partKey = part.partKey();
final Uri hostUri = host.hostUri();
final Uri nodeUri = nodeDef.nodeUri();
NodeBinding node = null;
if (nodeUri != null) {
node = this.kernel.createNode(this.spaceName, meshUri, partKey, hostUri, nodeDef);
if (node != null) {
node = host.openNode(nodeUri, node);
if (node != null) {
for (LaneDef laneDef : nodeDef.laneDefs()) {
createLane(edge, mesh, part, host, node, laneDef);
}
}
}
}
return node;
}
protected LaneBinding createLane(EdgeBinding edge, MeshBinding mesh, PartBinding part,
HostBinding host, NodeBinding node, LaneDef laneDef) {
final Uri meshUri = mesh.meshUri();
final Value partKey = part.partKey();
final Uri hostUri = host.hostUri();
final Uri nodeUri = node.nodeUri();
final Uri laneUri = laneDef.laneUri();
LaneBinding lane = null;
if (laneUri != null) {
lane = this.kernel.createLane(this.spaceName, meshUri, partKey, hostUri, nodeUri, laneDef);
if (lane != null) {
lane = node.openLane(laneUri, lane);
}
}
return lane;
}
protected EdgeBinding injectEdge(EdgeBinding edge) {
return this.kernel.injectEdge(this.spaceName, edge);
}
protected Log openEdgeLog() {
return this.kernel.openEdgeLog(this.spaceName);
}
protected Policy openEdgePolicy() {
return this.kernel.openEdgePolicy(this.spaceName);
}
protected Stage openEdgeStage() {
return this.kernel.openEdgeStage(this.spaceName);
}
protected StoreBinding openEdgeStore() {
return this.kernel.openEdgeStore(this.spaceName);
}
public MeshDef getMeshDef(Uri meshUri) {
MeshDef meshDef = this.fabricDef.getMeshDef(meshUri);
if (meshDef == null) {
meshDef = this.kernel.getMeshDef(this.spaceName, meshUri);
}
return meshDef;
}
@Override
public MeshBinding createMesh(Uri meshUri) {
return this.kernel.createMesh(this.spaceName, meshUri);
}
@Override
public MeshBinding injectMesh(Uri meshUri, MeshBinding mesh) {
final MeshDef meshDef = getMeshDef(meshUri);
return new FabricMesh(this.kernel.injectMesh(this.spaceName, meshUri, mesh), meshDef);
}
public Log openMeshLog(Uri meshUri) {
return this.kernel.openMeshLog(this.spaceName, meshUri);
}
public Policy openMeshPolicy(Uri meshUri) {
return this.kernel.openMeshPolicy(this.spaceName, meshUri);
}
public Stage openMeshStage(Uri meshUri) {
return this.kernel.openMeshStage(this.spaceName, meshUri);
}
public StoreBinding openMeshStore(Uri meshUri) {
return this.kernel.openMeshStore(this.spaceName, meshUri);
}
public PartDef getPartDef(Uri meshUri, Value partKey) {
PartDef partDef = this.fabricDef.getPartDef(partKey);
if (partDef == null) {
partDef = this.kernel.getPartDef(this.spaceName, meshUri, partKey);
}
return partDef;
}
@Override
public PartBinding createPart(Uri meshUri, Value partKey) {
return this.kernel.createPart(this.spaceName, meshUri, partKey);
}
@Override
public PartBinding injectPart(Uri meshUri, Value partKey, PartBinding part) {
return this.kernel.injectPart(this.spaceName, meshUri, partKey, part);
}
public Log openPartLog(Uri meshUri, Value partKey) {
return this.kernel.openPartLog(this.spaceName, meshUri, partKey);
}
public Policy openPartPolicy(Uri meshUri, Value partKey) {
return this.kernel.openPartPolicy(this.spaceName, meshUri, partKey);
}
public Stage openPartStage(Uri meshUri, Value partKey) {
return this.kernel.openPartStage(this.spaceName, meshUri, partKey);
}
public StoreBinding openPartStore(Uri meshUri, Value partKey) {
return this.kernel.openPartStore(this.spaceName, meshUri, partKey);
}
public HostDef getHostDef(Uri meshUri, Value partKey, Uri hostUri) {
HostDef hostDef = this.fabricDef.getHostDef(hostUri);
if (hostDef == null) {
hostDef = this.kernel.getHostDef(this.spaceName, meshUri, partKey, hostUri);
}
return hostDef;
}
@Override
public HostBinding createHost(Uri meshUri, Value partKey, Uri hostUri) {
return this.kernel.createHost(this.spaceName, meshUri, partKey, hostUri);
}
@Override
public HostBinding injectHost(Uri meshUri, Value partKey, Uri hostUri, HostBinding host) {
return this.kernel.injectHost(this.spaceName, meshUri, partKey, hostUri, host);
}
public Log openHostLog(Uri meshUri, Value partKey, Uri hostUri) {
return this.kernel.openHostLog(this.spaceName, meshUri, partKey, hostUri);
}
public Policy openHostPolicy(Uri meshUri, Value partKey, Uri hostUri) {
return this.kernel.openHostPolicy(this.spaceName, meshUri, partKey, hostUri);
}
public Stage openHostStage(Uri meshUri, Value partKey, Uri hostUri) {
return this.kernel.openHostStage(this.spaceName, meshUri, partKey, hostUri);
}
public StoreBinding openHostStore(Uri meshUri, Value partKey, Uri hostUri) {
return this.kernel.openHostStore(this.spaceName, meshUri, partKey, hostUri);
}
public NodeDef getNodeDef(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri) {
NodeDef nodeDef = this.fabricDef.getNodeDef(nodeUri);
if (nodeDef == null) {
nodeDef = this.kernel.getNodeDef(this.spaceName, meshUri, partKey, hostUri, nodeUri);
}
return nodeDef;
}
@Override
public NodeBinding createNode(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri) {
NodeBinding node = null;
if (!meshUri.isDefined()) {
final AgentFactory<?> agentFactory = this.agentFactories.get(nodeUri);
if (agentFactory != null) {
final Value props = agentFactory.props(nodeUri);
node = new AgentModel(props);
}
}
if (node == null) {
node = this.kernel.createNode(this.spaceName, meshUri, partKey, hostUri, nodeUri);
}
if (node == null && !meshUri.isDefined()) {
final NodeDef nodeDef = this.fabricDef.getNodeDef(nodeUri);
if (nodeDef != null) {
final Value props = nodeDef.props(nodeUri);
node = new AgentModel(props);
}
}
return node;
}
@Override
public NodeBinding injectNode(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, NodeBinding node) {
return this.kernel.injectNode(this.spaceName, meshUri, partKey, hostUri, nodeUri, node);
}
public Log openNodeLog(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri) {
return this.kernel.openNodeLog(this.spaceName, meshUri, partKey, hostUri, nodeUri);
}
public Policy openNodePolicy(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri) {
return this.kernel.openNodePolicy(this.spaceName, meshUri, partKey, hostUri, nodeUri);
}
public Stage openNodeStage(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri) {
return this.kernel.openNodeStage(this.spaceName, meshUri, partKey, hostUri, nodeUri);
}
public StoreBinding openNodeStore(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri) {
return this.kernel.openNodeStore(this.spaceName, meshUri, partKey, hostUri, nodeUri);
}
public LaneDef getLaneDef(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri) {
LaneDef laneDef = this.fabricDef.getLaneDef(laneUri);
if (laneDef == null) {
laneDef = this.kernel.getLaneDef(this.spaceName, meshUri, partKey, hostUri, nodeUri, laneUri);
}
return laneDef;
}
@Override
public LaneBinding createLane(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, LaneDef laneDef) {
return this.kernel.createLane(this.spaceName, meshUri, partKey, hostUri, nodeUri, laneDef);
}
@Override
public LaneBinding createLane(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri) {
return this.kernel.createLane(this.spaceName, meshUri, partKey, hostUri, nodeUri, laneUri);
}
@Override
public LaneBinding injectLane(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri, LaneBinding lane) {
return this.kernel.injectLane(this.spaceName, meshUri, partKey, hostUri, nodeUri, laneUri, lane);
}
@Override
public void openLanes(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, NodeBinding node) {
this.kernel.openLanes(this.spaceName, meshUri, partKey, hostUri, nodeUri, node);
}
public Log openLaneLog(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri) {
return this.kernel.openLaneLog(this.spaceName, meshUri, partKey, hostUri, nodeUri, laneUri);
}
public Policy openLanePolicy(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri) {
return this.kernel.openLanePolicy(this.spaceName, meshUri, partKey, hostUri, nodeUri, laneUri);
}
public Stage openLaneStage(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri) {
return this.kernel.openLaneStage(this.spaceName, meshUri, partKey, hostUri, nodeUri, laneUri);
}
public StoreBinding openLaneStore(Uri meshUri, Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri) {
return this.kernel.openLaneStore(this.spaceName, meshUri, partKey, hostUri, nodeUri, laneUri);
}
@Override
public PolicyDirective<Identity> authenticate(Credentials credentials) {
PolicyDirective<Identity> directive = null;
final HashTrieMap<String, Authenticator> authenticators = this.authenticators;
if (!authenticators.isEmpty()) {
for (Authenticator authenticator : authenticators.values()) {
directive = authenticator.authenticate(credentials);
if (directive != null) {
break;
}
}
} else {
final Identity identity = new FabricIdentity(credentials.requestUri(), credentials.fromUri(), Value.absent());
directive = PolicyDirective.<Identity>allow(identity);
}
return directive;
}
@Override
public LinkBinding bindDownlink(Downlink downlink) {
return this.edge.bindDownlink(downlink);
}
@Override
public void openDownlink(LinkBinding link) {
this.edge.openDownlink(link);
}
@Override
public void closeDownlink(LinkBinding link) {
// nop
}
@Override
public void pushDown(PushRequest pushRequest) {
this.edge.pushDown(pushRequest);
}
@Override
public void trace(Object message) {
final Log log = this.log;
if (log != null) {
log.trace(message);
} else {
this.kernel.trace(message);
}
}
@Override
public void debug(Object message) {
final Log log = this.log;
if (log != null) {
log.debug(message);
} else {
this.kernel.debug(message);
}
}
@Override
public void info(Object message) {
final Log log = this.log;
if (log != null) {
log.info(message);
} else {
this.kernel.info(message);
}
}
@Override
public void warn(Object message) {
final Log log = this.log;
if (log != null) {
log.warn(message);
} else {
this.kernel.warn(message);
}
}
@Override
public void error(Object message) {
final Log log = this.log;
if (log != null) {
log.error(message);
} else {
this.kernel.error(message);
}
}
@Override
public void open() {
this.edge.open();
}
@Override
public void load() {
this.edge.load();
}
@Override
public void start() {
this.edge.start();
}
@Override
public void stop() {
this.edge.stop();
}
@Override
public void unload() {
this.edge.unload();
}
@Override
public void close() {
this.edge.close();
}
@Override
public void willOpen() {
if (this.log == null) {
this.log = openLog();
}
if (this.policy == null) {
this.policy = openPolicy();
}
if (this.stage == null) {
this.stage = openStage();
}
if (this.store == null) {
this.store = openStore();
}
this.open();
}
@Override
public void didOpen() {
// nop
}
@Override
public void willLoad() {
this.load();
}
@Override
public void didLoad() {
// nop
}
@Override
public void willStart() {
for (Plane plane : this.planes.values()) {
plane.willStart();
}
this.start();
}
@Override
public void didStart() {
for (Plane plane : this.planes.values()) {
plane.didStart();
}
}
@Override
public void willStop() {
for (Plane plane : this.planes.values()) {
plane.willStop();
}
this.stop();
}
@Override
public void didStop() {
for (Plane plane : this.planes.values()) {
plane.didStop();
}
}
@Override
public void willUnload() {
this.unload();
}
@Override
public void didUnload() {
// nop
}
@Override
public void willClose() {
for (Plane plane : this.planes.values()) {
plane.willClose();
}
this.close();
}
@Override
public void didClose() {
for (Plane plane : this.planes.values()) {
plane.didClose();
}
closeStore();
closeStage();
closePolicy();
closeLog();
}
@Override
public void didFail(Throwable error) {
for (Plane plane : this.planes.values()) {
plane.didFail(error);
}
}
@SuppressWarnings("unchecked")
static final AtomicReferenceFieldUpdater<Fabric, HashTrieMap<String, Plane>> PLANES =
AtomicReferenceFieldUpdater.newUpdater(Fabric.class, (Class<HashTrieMap<String, Plane>>) (Class<?>) HashTrieMap.class, "planes");
@SuppressWarnings("unchecked")
static final AtomicReferenceFieldUpdater<Fabric, HashTrieMap<String, AgentRoute<?>>> AGENT_ROUTES =
AtomicReferenceFieldUpdater.newUpdater(Fabric.class, (Class<HashTrieMap<String, AgentRoute<?>>>) (Class<?>) HashTrieMap.class, "agentRoutes");
@SuppressWarnings("unchecked")
static final AtomicReferenceFieldUpdater<Fabric, UriMapper<AgentFactory<?>>> AGENT_FACTORIES =
AtomicReferenceFieldUpdater.newUpdater(Fabric.class, (Class<UriMapper<AgentFactory<?>>>) (Class<?>) UriMapper.class, "agentFactories");
@SuppressWarnings("unchecked")
static final AtomicReferenceFieldUpdater<Fabric, HashTrieMap<String, Authenticator>> AUTHENTICATORS =
AtomicReferenceFieldUpdater.newUpdater(Fabric.class, (Class<HashTrieMap<String, Authenticator>>) (Class<?>) HashTrieMap.class, "authenticators");
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricAgentRoute.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.fabric;
import swim.api.agent.AgentRouteContext;
import swim.uri.UriPattern;
public class FabricAgentRoute implements AgentRouteContext {
final String routeName;
final UriPattern pattern;
public FabricAgentRoute(String routeName, UriPattern pattern) {
this.routeName = routeName;
this.pattern = pattern;
}
@Override
public final String routeName() {
return this.routeName;
}
@Override
public final UriPattern pattern() {
return this.pattern;
}
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricAuthenticator.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.fabric;
import java.net.InetSocketAddress;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import swim.api.auth.Authenticator;
import swim.api.auth.AuthenticatorContext;
import swim.concurrent.MainStage;
import swim.concurrent.Schedule;
import swim.concurrent.Stage;
import swim.io.IpService;
import swim.io.IpServiceRef;
import swim.io.IpSettings;
import swim.io.IpSocket;
import swim.io.IpSocketRef;
import swim.kernel.KernelContext;
import swim.util.Log;
public class FabricAuthenticator implements AuthenticatorContext {
final String authenticatorName;
final KernelContext kernel;
Authenticator authenticator;
volatile int status;
Log log;
Stage stage;
public FabricAuthenticator(String authenticatorName, KernelContext kernel) {
this.authenticatorName = authenticatorName;
this.kernel = kernel;
}
public final String authenticatorName() {
return this.authenticatorName;
}
@Override
public Schedule schedule() {
return this.stage;
}
@Override
public final Stage stage() {
return this.stage;
}
public final KernelContext kernel() {
return this.kernel;
}
public final Authenticator authenticator() {
return this.authenticator;
}
public void setAuthenticator(Authenticator authenticator) {
this.authenticator = authenticator;
}
@Override
public IpSettings ipSettings() {
return this.kernel.ipSettings();
}
@Override
public IpServiceRef bindTcp(InetSocketAddress localAddress, IpService service, IpSettings ipSettings) {
return this.kernel.bindTcp(localAddress, service, ipSettings);
}
@Override
public IpServiceRef bindTls(InetSocketAddress localAddress, IpService service, IpSettings ipSettings) {
return this.kernel.bindTls(localAddress, service, ipSettings);
}
@Override
public IpSocketRef connectTcp(InetSocketAddress remoteAddress, IpSocket socket, IpSettings ipSettings) {
return this.kernel.connectTcp(remoteAddress, socket, ipSettings);
}
@Override
public IpSocketRef connectTls(InetSocketAddress remoteAddress, IpSocket socket, IpSettings ipSettings) {
return this.kernel.connectTls(remoteAddress, socket, ipSettings);
}
protected Log openLog() {
return this.kernel.openAuthenticatorLog(this.authenticatorName);
}
protected void closeLog() {
this.log = null;
}
protected Stage openStage() {
return this.kernel.openAuthenticatorStage(this.authenticatorName);
}
protected void closeStage() {
final Stage stage = this.stage;
if (stage instanceof MainStage) {
((MainStage) stage).stop();
}
this.stage = null;
}
public void start() {
int oldStatus;
int newStatus;
do {
oldStatus = this.status;
newStatus = oldStatus | STARTED;
} while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus));
if ((oldStatus & STARTED) == 0) {
willStart();
didStart();
}
}
public void stop() {
int oldStatus;
int newStatus;
do {
oldStatus = this.status;
newStatus = oldStatus & ~STARTED;
} while (oldStatus != newStatus && !STATUS.compareAndSet(this, oldStatus, newStatus));
if ((oldStatus & STARTED) != 0) {
willStop();
didStop();
}
}
protected void willStart() {
this.log = openLog();
this.stage = openStage();
this.authenticator.willStart();
}
protected void didStart() {
this.authenticator.didStart();
}
protected void willStop() {
this.authenticator.willStop();
}
protected void didStop() {
this.authenticator.didStop();
closeStage();
closeLog();
}
@Override
public void trace(Object message) {
final Log log = this.log;
if (log != null) {
log.trace(message);
} else {
this.kernel.trace(message);
}
}
@Override
public void debug(Object message) {
final Log log = this.log;
if (log != null) {
log.debug(message);
} else {
this.kernel.debug(message);
}
}
@Override
public void info(Object message) {
final Log log = this.log;
if (log != null) {
log.info(message);
} else {
this.kernel.info(message);
}
}
@Override
public void warn(Object message) {
final Log log = this.log;
if (log != null) {
log.warn(message);
} else {
this.kernel.warn(message);
}
}
@Override
public void error(Object message) {
final Log log = this.log;
if (log != null) {
log.error(message);
} else {
this.kernel.error(message);
}
}
protected static final int STARTED = 0x01;
protected static final AtomicIntegerFieldUpdater<FabricAuthenticator> STATUS =
AtomicIntegerFieldUpdater.newUpdater(FabricAuthenticator.class, "status");
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricCell.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.fabric;
import swim.api.Downlink;
import swim.api.policy.Policy;
import swim.concurrent.Schedule;
import swim.concurrent.Stage;
import swim.runtime.CellBinding;
import swim.runtime.CellContext;
import swim.runtime.LinkBinding;
import swim.runtime.PushRequest;
import swim.store.StoreBinding;
import swim.uri.Uri;
import swim.util.Log;
public abstract class FabricCell implements CellBinding, CellContext {
Log log;
Policy policy;
public abstract CellBinding cellBinding();
public abstract CellContext cellContext();
@Override
public Uri meshUri() {
return cellContext().meshUri();
}
@Override
public Policy policy() {
final Policy policy = this.policy;
return policy != null ? policy : cellContext().policy();
}
@Override
public Schedule schedule() {
return cellContext().schedule();
}
@Override
public Stage stage() {
return cellContext().stage();
}
@Override
public StoreBinding store() {
return cellContext().store();
}
protected Log openLog() {
return null;
}
protected void closeLog() {
this.log = null;
}
protected Policy openPolicy() {
return null;
}
protected void closePolicy() {
this.policy = null;
}
@Override
public LinkBinding bindDownlink(Downlink downlink) {
return cellContext().bindDownlink(downlink);
}
@Override
public void openDownlink(LinkBinding link) {
cellContext().openDownlink(link);
}
@Override
public void closeDownlink(LinkBinding link) {
cellContext().closeDownlink(link);
}
@Override
public void pushDown(PushRequest pushRequest) {
cellContext().pushDown(pushRequest);
}
@Override
public void openUplink(LinkBinding link) {
cellBinding().openUplink(link);
}
@Override
public void pushUp(PushRequest pushRequest) {
cellBinding().pushUp(pushRequest);
}
@Override
public void trace(Object message) {
final Log log = this.log;
if (log != null) {
log.trace(message);
} else {
cellContext().trace(message);
}
}
@Override
public void debug(Object message) {
final Log log = this.log;
if (log != null) {
log.debug(message);
} else {
cellContext().debug(message);
}
}
@Override
public void info(Object message) {
final Log log = this.log;
if (log != null) {
log.info(message);
} else {
cellContext().info(message);
}
}
@Override
public void warn(Object message) {
final Log log = this.log;
if (log != null) {
log.warn(message);
} else {
cellContext().warn(message);
}
}
@Override
public void error(Object message) {
final Log log = this.log;
if (log != null) {
log.error(message);
} else {
cellContext().error(message);
}
}
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricDef.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.fabric;
import java.util.Collection;
import swim.api.auth.AuthenticatorDef;
import swim.api.plane.PlaneDef;
import swim.api.space.SpaceDef;
import swim.codec.Debug;
import swim.codec.Format;
import swim.codec.Output;
import swim.collections.FingerTrieSeq;
import swim.collections.HashTrieMap;
import swim.concurrent.StageDef;
import swim.runtime.EdgeDef;
import swim.runtime.HostDef;
import swim.runtime.LaneDef;
import swim.runtime.LogDef;
import swim.runtime.MeshDef;
import swim.runtime.NodeDef;
import swim.runtime.PartDef;
import swim.runtime.PolicyDef;
import swim.store.StoreDef;
import swim.structure.Value;
import swim.uri.Uri;
import swim.uri.UriMapper;
import swim.util.Murmur3;
public class FabricDef implements SpaceDef, EdgeDef, Debug {
final String spaceName;
final FingerTrieSeq<PlaneDef> planeDefs;
final HashTrieMap<String, AuthenticatorDef> authenticatorDefs;
final HashTrieMap<Uri, MeshDef> meshDefs;
final HashTrieMap<Value, PartDef> partDefs;
final UriMapper<HostDef> hostDefs;
final UriMapper<NodeDef> nodeDefs;
final UriMapper<LaneDef> laneDefs;
final LogDef logDef;
final PolicyDef policyDef;
final StageDef stageDef;
final StoreDef storeDef;
public FabricDef(String spaceName, FingerTrieSeq<PlaneDef> planeDefs,
HashTrieMap<String, AuthenticatorDef> authenticatorDefs,
HashTrieMap<Uri, MeshDef> meshDefs, HashTrieMap<Value, PartDef> partDefs,
UriMapper<HostDef> hostDefs, UriMapper<NodeDef> nodeDefs,
UriMapper<LaneDef> laneDefs, LogDef logDef, PolicyDef policyDef,
StageDef stageDef, StoreDef storeDef) {
this.spaceName = spaceName;
this.planeDefs = planeDefs;
this.authenticatorDefs = authenticatorDefs;
this.meshDefs = meshDefs;
this.partDefs = partDefs;
this.hostDefs = hostDefs;
this.nodeDefs = nodeDefs;
this.laneDefs = laneDefs;
this.logDef = logDef;
this.policyDef = policyDef;
this.stageDef = stageDef;
this.storeDef = storeDef;
}
@Override
public final String spaceName() {
return this.spaceName;
}
public FabricDef spaceName(String spaceName) {
return copy(spaceName, this.planeDefs, this.authenticatorDefs, this.meshDefs,
this.partDefs, this.hostDefs, this.nodeDefs, this.laneDefs,
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends PlaneDef> planeDefs() {
return this.planeDefs;
}
@Override
public final PlaneDef getPlaneDef(String planeName) {
for (PlaneDef planeDef : this.planeDefs) {
if (planeName.equals(planeDef.planeName())) {
return planeDef;
}
}
return null;
}
public FabricDef planeDef(PlaneDef planeDef) {
return copy(this.spaceName, this.planeDefs.appended(planeDef),
this.authenticatorDefs, this.meshDefs, this.partDefs, this.hostDefs,
this.nodeDefs, this.laneDefs, this.logDef, this.policyDef,
this.stageDef, this.storeDef);
}
public final Collection<? extends AuthenticatorDef> authenticatorDefs() {
return this.authenticatorDefs.values();
}
public final AuthenticatorDef getAuthenticatorDef(String authenticatorDef) {
return this.authenticatorDefs.get(authenticatorDef);
}
public FabricDef authenticatorDef(AuthenticatorDef authenticatorDef) {
return copy(this.spaceName, this.planeDefs,
this.authenticatorDefs.updated(authenticatorDef.authenticatorName(), authenticatorDef),
this.meshDefs, this.partDefs, this.hostDefs, this.nodeDefs, this.laneDefs,
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends MeshDef> meshDefs() {
return this.meshDefs.values();
}
@Override
public final MeshDef getMeshDef(Uri meshUri) {
return this.meshDefs.get(meshUri);
}
public FabricDef meshDef(MeshDef meshDef) {
return copy(this.spaceName, this.planeDefs, this.authenticatorDefs,
this.meshDefs.updated(meshDef.meshUri(), meshDef),
this.partDefs, this.hostDefs, this.nodeDefs, this.laneDefs,
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends PartDef> partDefs() {
return this.partDefs.values();
}
@Override
public final PartDef getPartDef(Value partKey) {
return this.partDefs.get(partKey);
}
public FabricDef partDef(PartDef partDef) {
return copy(this.spaceName, this.planeDefs, this.authenticatorDefs,
this.meshDefs, this.partDefs.updated(partDef.partKey(), partDef),
this.hostDefs, this.nodeDefs, this.laneDefs,
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends HostDef> hostDefs() {
return this.hostDefs.values();
}
@Override
public final HostDef getHostDef(Uri hostUri) {
return this.hostDefs.get(hostUri);
}
public FabricDef hostDef(HostDef hostDef) {
return copy(this.spaceName, this.planeDefs, this.authenticatorDefs, this.meshDefs,
this.partDefs, this.hostDefs.updated(hostDef.hostPattern(), hostDef),
this.nodeDefs, this.laneDefs, this.logDef, this.policyDef,
this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends NodeDef> nodeDefs() {
return this.nodeDefs.values();
}
@Override
public final NodeDef getNodeDef(Uri nodeUri) {
return this.nodeDefs.get(nodeUri);
}
public FabricDef nodeDef(NodeDef nodeDef) {
return copy(this.spaceName, this.planeDefs, this.authenticatorDefs,
this.meshDefs, this.partDefs, this.hostDefs,
this.nodeDefs.updated(nodeDef.nodePattern(), nodeDef), this.laneDefs,
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends LaneDef> laneDefs() {
return this.laneDefs.values();
}
@Override
public final LaneDef getLaneDef(Uri laneUri) {
return this.laneDefs.get(laneUri);
}
public FabricDef laneDef(LaneDef laneDef) {
return copy(this.spaceName, this.planeDefs, this.authenticatorDefs,
this.meshDefs, this.partDefs, this.hostDefs, this.nodeDefs,
this.laneDefs.updated(laneDef.lanePattern(), laneDef),
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final LogDef logDef() {
return this.logDef;
}
public FabricDef logDef(LogDef logDef) {
return copy(this.spaceName, this.planeDefs, this.authenticatorDefs,
this.meshDefs, this.partDefs, this.hostDefs, this.nodeDefs, this.laneDefs,
logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final PolicyDef policyDef() {
return this.policyDef;
}
public FabricDef policyDef(PolicyDef policyDef) {
return copy(this.spaceName, this.planeDefs, this.authenticatorDefs,
this.meshDefs, this.partDefs, this.hostDefs, this.nodeDefs, this.laneDefs,
this.logDef, policyDef, this.stageDef, this.storeDef);
}
@Override
public final StageDef stageDef() {
return this.stageDef;
}
public FabricDef stageDef(StageDef stageDef) {
return copy(this.spaceName, this.planeDefs, this.authenticatorDefs,
this.meshDefs, this.partDefs, this.hostDefs, this.nodeDefs, this.laneDefs,
this.logDef, this.policyDef, stageDef, this.storeDef);
}
@Override
public final StoreDef storeDef() {
return this.storeDef;
}
public FabricDef storeDef(StoreDef storeDef) {
return copy(this.spaceName, this.planeDefs, this.authenticatorDefs,
this.meshDefs, this.partDefs, this.hostDefs, this.nodeDefs, this.laneDefs,
this.logDef, this.policyDef, this.stageDef, storeDef);
}
protected FabricDef copy(String spaceName, FingerTrieSeq<PlaneDef> planeDefs,
HashTrieMap<String, AuthenticatorDef> authenticatorDefs,
HashTrieMap<Uri, MeshDef> meshDefs, HashTrieMap<Value, PartDef> partDefs,
UriMapper<HostDef> hostDefs, UriMapper<NodeDef> nodeDefs,
UriMapper<LaneDef> laneDefs, LogDef logDef, PolicyDef policyDef,
StageDef stageDef, StoreDef storeDef) {
return new FabricDef(spaceName, planeDefs, authenticatorDefs, meshDefs,
partDefs, hostDefs, nodeDefs, laneDefs,
logDef, policyDef, stageDef, storeDef);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof FabricDef) {
final FabricDef that = (FabricDef) other;
return (this.spaceName == null ? that.spaceName == null : this.spaceName.equals(that.spaceName))
&& this.planeDefs.equals(that.planeDefs)
&& this.authenticatorDefs.equals(that.authenticatorDefs)
&& this.meshDefs.equals(that.meshDefs)
&& this.partDefs.equals(that.partDefs)
&& this.hostDefs.equals(that.hostDefs)
&& this.nodeDefs.equals(that.nodeDefs)
&& this.laneDefs.equals(that.laneDefs)
&& (this.logDef == null ? that.logDef == null : this.logDef.equals(that.logDef))
&& (this.policyDef == null ? that.policyDef == null : this.policyDef.equals(that.policyDef))
&& (this.stageDef == null ? that.stageDef == null : this.stageDef.equals(that.stageDef))
&& (this.storeDef == null ? that.storeDef == null : this.storeDef.equals(that.storeDef));
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(FabricDef.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(
Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(hashSeed,
Murmur3.hash(this.spaceName)), this.planeDefs.hashCode()), this.authenticatorDefs.hashCode()),
this.meshDefs.hashCode()), this.partDefs.hashCode()), this.hostDefs.hashCode()),
this.nodeDefs.hashCode()), this.laneDefs.hashCode()), Murmur3.hash(this.logDef)),
Murmur3.hash(this.policyDef)), Murmur3.hash(this.stageDef)), Murmur3.hash(this.storeDef)));
}
@Override
public void debug(Output<?> output) {
output = output.write("FabricDef").write('.').write("fromName").write('(')
.debug(this.spaceName).write(')');
for (PlaneDef planeDef : this.planeDefs) {
output = output.write('.').write("planeDef").write('(').debug(planeDef).write(')');
}
for (AuthenticatorDef authenticatorDef : this.authenticatorDefs.values()) {
output = output.write('.').write("authenticatorDef").write('(').debug(authenticatorDef).write(')');
}
for (MeshDef meshDef : this.meshDefs.values()) {
output = output.write('.').write("meshDef").write('(').debug(meshDef).write(')');
}
for (PartDef partDef : this.partDefs.values()) {
output = output.write('.').write("partDef").write('(').debug(partDef).write(')');
}
for (HostDef hostDef : this.hostDefs.values()) {
output = output.write('.').write("hostDef").write('(').debug(hostDef).write(')');
}
for (NodeDef nodeDef : this.nodeDefs.values()) {
output = output.write('.').write("nodeDef").write('(').debug(nodeDef).write(')');
}
for (LaneDef laneDef : this.laneDefs.values()) {
output = output.write('.').write("laneDef").write('(').debug(laneDef).write(')');
}
if (this.logDef != null) {
output = output.write('.').write("logDef").write('(').debug(this.logDef).write(')');
}
if (this.policyDef != null) {
output = output.write('.').write("policyDef").write('(').debug(this.policyDef).write(')');
}
if (this.stageDef != null) {
output = output.write('.').write("stageDef").write('(').debug(this.stageDef).write(')');
}
if (this.storeDef != null) {
output = output.write('.').write("storeDef").write('(').debug(this.storeDef).write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
public static FabricDef fromName(String spaceName) {
return new FabricDef(spaceName, FingerTrieSeq.empty(), HashTrieMap.empty(),
HashTrieMap.empty(), HashTrieMap.empty(), UriMapper.empty(),
UriMapper.empty(), UriMapper.empty(), null, null, null, null);
}
public static FabricDef fromPlaneDef(PlaneDef planeDef) {
return new FabricDef(planeDef.planeName(), FingerTrieSeq.of(planeDef), HashTrieMap.empty(),
HashTrieMap.empty(), HashTrieMap.empty(), UriMapper.empty(),
UriMapper.empty(), UriMapper.empty(), null, null, null, null);
}
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricHost.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.fabric;
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.Stage;
import swim.concurrent.StageDef;
import swim.runtime.CellBinding;
import swim.runtime.CellContext;
import swim.runtime.HostBinding;
import swim.runtime.HostContext;
import swim.runtime.HostDef;
import swim.runtime.LaneBinding;
import swim.runtime.LaneDef;
import swim.runtime.LogDef;
import swim.runtime.NodeBinding;
import swim.runtime.NodeDef;
import swim.runtime.PartBinding;
import swim.runtime.PolicyDef;
import swim.runtime.agent.AgentModel;
import swim.store.StoreBinding;
import swim.store.StoreDef;
import swim.structure.Value;
import swim.uri.Uri;
import swim.util.Log;
public class FabricHost extends FabricTier implements HostBinding, HostContext {
final HostBinding hostBinding;
HostContext hostContext;
HostDef hostDef;
public FabricHost(HostBinding hostBinding, HostDef hostDef) {
this.hostBinding = hostBinding;
this.hostDef = hostDef;
}
public final HostDef hostDef() {
return this.hostDef;
}
public final FabricPart fabricPart() {
return part().unwrapPart(FabricPart.class);
}
@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 this.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 final CellBinding cellBinding() {
return this.hostBinding;
}
@Override
public final CellContext cellContext() {
return this.hostContext;
}
@Override
public Value partKey() {
return this.hostContext.partKey();
}
@Override
public Uri hostUri() {
return this.hostContext.hostUri();
}
@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);
}
public Log createLog(LogDef logDef) {
final FabricPart part = fabricPart();
return part != null ? part.createLog(logDef) : null;
}
public Log injectLog(Log log) {
final FabricPart part = fabricPart();
return part != null ? part.injectLog(log) : log;
}
@Override
protected Log openLog() {
Log log;
if (this.hostDef != null && this.hostDef.logDef() != null) {
log = createLog(this.hostDef.logDef());
} else {
log = openHostLog();
}
if (log != null) {
log = injectLog(log);
}
return log;
}
public Policy createPolicy(PolicyDef policyDef) {
final FabricPart part = fabricPart();
return part != null ? part.createPolicy(policyDef) : null;
}
public Policy injectPolicy(Policy policy) {
final FabricPart part = fabricPart();
return part != null ? part.injectPolicy(policy) : policy;
}
@Override
protected Policy openPolicy() {
Policy policy;
if (this.hostDef != null && this.hostDef.policyDef() != null) {
policy = createPolicy(this.hostDef.policyDef());
} else {
policy = openHostPolicy();
}
if (policy != null) {
policy = injectPolicy(policy);
}
return policy;
}
public Stage createStage(StageDef stageDef) {
final FabricPart part = fabricPart();
return part != null ? part.createStage(stageDef) : null;
}
public Stage injectStage(Stage stage) {
final FabricPart part = fabricPart();
return part != null ? part.injectStage(stage) : stage;
}
@Override
protected Stage openStage() {
Stage stage;
if (this.hostDef != null && this.hostDef.stageDef() != null) {
stage = createStage(this.hostDef.stageDef());
} else {
stage = openHostStage();
}
if (stage != null) {
stage = injectStage(stage);
}
return stage;
}
public StoreBinding createStore(StoreDef storeDef) {
final FabricPart part = fabricPart();
return part != null ? part.createStore(storeDef) : null;
}
public StoreBinding injectStore(StoreBinding store) {
final FabricPart part = fabricPart();
return part != null ? part.injectStore(store) : store;
}
@Override
protected StoreBinding openStore() {
StoreBinding store = null;
if (this.hostDef != null && this.hostDef.storeDef() != null) {
store = createStore(this.hostDef.storeDef());
} else {
store = openHostStore();
}
if (store != null) {
store = injectStore(store);
}
return store;
}
protected Log openHostLog() {
final FabricPart part = fabricPart();
return part != null ? part.openHostLog(hostUri()) : null;
}
protected Policy openHostPolicy() {
final FabricPart part = fabricPart();
return part != null ? part.openHostPolicy(hostUri()) : null;
}
protected Stage openHostStage() {
final FabricPart part = fabricPart();
return part != null ? part.openHostStage(hostUri()) : null;
}
protected StoreBinding openHostStore() {
final FabricPart part = fabricPart();
return part != null ? part.openHostStore(hostUri()) : null;
}
public NodeDef getNodeDef(Uri nodeUri) {
final HostDef hostDef = this.hostDef;
NodeDef nodeDef = hostDef != null ? hostDef.getNodeDef(nodeUri) : null;
if (nodeDef == null) {
final FabricPart part = fabricPart();
nodeDef = part != null ? part.getNodeDef(hostUri(), nodeUri) : null;
}
return nodeDef;
}
@Override
public NodeBinding createNode(Uri nodeUri) {
NodeBinding node = this.hostContext.createNode(nodeUri);
if (node == null && !meshUri().isDefined()) {
final HostDef hostDef = this.hostDef;
final NodeDef nodeDef = hostDef != null ? hostDef.getNodeDef(nodeUri) : null;
if (nodeDef != null) {
final Value props = nodeDef.props(nodeUri);
node = new AgentModel(props);
}
}
return node;
}
@Override
public NodeBinding injectNode(Uri nodeUri, NodeBinding node) {
final NodeDef nodeDef = getNodeDef(nodeUri);
return new FabricNode(this.hostContext.injectNode(nodeUri, node), nodeDef);
}
public Log openNodeLog(Uri nodeUri) {
final FabricPart part = fabricPart();
return part != null ? part.openNodeLog(hostUri(), nodeUri) : null;
}
public Policy openNodePolicy(Uri nodeUri) {
final FabricPart part = fabricPart();
return part != null ? part.openNodePolicy(hostUri(), nodeUri) : null;
}
public Stage openNodeStage(Uri nodeUri) {
final FabricPart part = fabricPart();
return part != null ? part.openNodeStage(hostUri(), nodeUri) : null;
}
public StoreBinding openNodeStore(Uri nodeUri) {
final FabricPart part = fabricPart();
return part != null ? part.openNodeStore(hostUri(), nodeUri) : null;
}
public LaneDef getLaneDef(Uri nodeUri, Uri laneUri) {
final HostDef hostDef = this.hostDef;
LaneDef laneDef = hostDef != null ? hostDef.getLaneDef(laneUri) : null;
if (laneDef == null) {
final FabricPart part = fabricPart();
laneDef = part != null ? part.getLaneDef(hostUri(), nodeUri, laneUri) : null;
}
return laneDef;
}
@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);
}
public Log openLaneLog(Uri nodeUri, Uri laneUri) {
final FabricPart part = fabricPart();
return part != null ? part.openLaneLog(hostUri(), nodeUri, laneUri) : null;
}
public Policy openLanePolicy(Uri nodeUri, Uri laneUri) {
final FabricPart part = fabricPart();
return part != null ? part.openLanePolicy(hostUri(), nodeUri, laneUri) : null;
}
public Stage openLaneStage(Uri nodeUri, Uri laneUri) {
final FabricPart part = fabricPart();
return part != null ? part.openLaneStage(hostUri(), nodeUri, laneUri) : null;
}
public StoreBinding openLaneStore(Uri nodeUri, Uri laneUri) {
final FabricPart part = fabricPart();
return part != null ? part.openLaneStore(hostUri(), nodeUri, laneUri) : null;
}
@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);
if (!meshUri().isDefined()) {
final HostDef hostDef = this.hostDef;
final NodeDef nodeDef = hostDef != null ? hostDef.getNodeDef(nodeUri) : null;
if (nodeDef != null && node instanceof AgentModel) {
final AgentModel agentModel = (AgentModel) node;
for (AgentDef agentDef : nodeDef.agentDefs()) {
final AgentFactory<?> agentFactory = createAgentFactory(nodeUri, agentDef);
if (agentDef != null) {
Value props = agentDef.props();
if (!props.isDefined()) {
props = agentModel.props();
}
agentModel.addAgentView(agentModel.createAgent(agentFactory, props));
}
}
}
}
}
@Override
public PolicyDirective<Identity> authenticate(Credentials credentials) {
return this.hostContext.authenticate(credentials);
}
@Override
public void didConnect() {
this.hostContext.didConnect();
}
@Override
public void didDisconnect() {
this.hostContext.didDisconnect();
}
@Override
public void didClose() {
this.hostBinding.didClose();
}
@Override
public void didFail(Throwable error) {
this.hostBinding.didFail(error);
}
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricHostDef.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.fabric;
import java.util.Collection;
import swim.codec.Debug;
import swim.codec.Format;
import swim.codec.Output;
import swim.concurrent.StageDef;
import swim.runtime.HostDef;
import swim.runtime.LaneDef;
import swim.runtime.LogDef;
import swim.runtime.NodeDef;
import swim.runtime.PolicyDef;
import swim.store.StoreDef;
import swim.uri.Uri;
import swim.uri.UriMapper;
import swim.uri.UriPattern;
import swim.util.Murmur3;
public class FabricHostDef implements HostDef, Debug {
final UriPattern hostPattern;
final boolean isPrimary;
final boolean isReplica;
final UriMapper<NodeDef> nodeDefs;
final UriMapper<LaneDef> laneDefs;
final LogDef logDef;
final PolicyDef policyDef;
final StageDef stageDef;
final StoreDef storeDef;
public FabricHostDef(UriPattern hostPattern, boolean isPrimary, boolean isReplica,
UriMapper<NodeDef> nodeDefs, UriMapper<LaneDef> laneDefs,
LogDef logDef, PolicyDef policyDef, StageDef stageDef,
StoreDef storeDef) {
this.hostPattern = hostPattern;
this.isPrimary = isPrimary;
this.isReplica = isReplica;
this.nodeDefs = nodeDefs;
this.laneDefs = laneDefs;
this.logDef = logDef;
this.policyDef = policyDef;
this.stageDef = stageDef;
this.storeDef = storeDef;
}
@Override
public final Uri hostUri() {
return this.hostPattern.isUri() ? this.hostPattern.toUri() : null;
}
@Override
public final UriPattern hostPattern() {
return this.hostPattern;
}
public FabricHostDef hostPattern(UriPattern hostPattern) {
return copy(hostPattern, this.isPrimary, this.isReplica, this.nodeDefs, this.laneDefs,
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final boolean isPrimary() {
return this.isPrimary;
}
public FabricHostDef isPrimary(boolean isPrimary) {
return copy(this.hostPattern, isPrimary, this.isReplica, this.nodeDefs, this.laneDefs,
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final boolean isReplica() {
return this.isReplica;
}
public FabricHostDef isReplica(boolean isReplica) {
return copy(this.hostPattern, this.isPrimary, isReplica, this.nodeDefs, this.laneDefs,
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends NodeDef> nodeDefs() {
return this.nodeDefs.values();
}
@Override
public final NodeDef getNodeDef(Uri nodeUri) {
return this.nodeDefs.get(nodeUri);
}
public FabricHostDef nodeDef(NodeDef nodeDef) {
return copy(this.hostPattern, this.isPrimary, this.isReplica,
this.nodeDefs.updated(nodeDef.nodePattern(), nodeDef), this.laneDefs,
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends LaneDef> laneDefs() {
return this.laneDefs.values();
}
@Override
public final LaneDef getLaneDef(Uri laneUri) {
return this.laneDefs.get(laneUri);
}
public FabricHostDef laneDef(LaneDef laneDef) {
return copy(this.hostPattern, this.isPrimary, this.isReplica,
this.nodeDefs, this.laneDefs.updated(laneDef.lanePattern(), laneDef),
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final LogDef logDef() {
return this.logDef;
}
public FabricHostDef logDef(LogDef logDef) {
return copy(this.hostPattern, this.isPrimary, this.isReplica, this.nodeDefs, this.laneDefs,
logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final PolicyDef policyDef() {
return this.policyDef;
}
public FabricHostDef policyDef(PolicyDef policyDef) {
return copy(this.hostPattern, this.isPrimary, this.isReplica, this.nodeDefs, this.laneDefs,
this.logDef, policyDef, this.stageDef, this.storeDef);
}
@Override
public final StageDef stageDef() {
return this.stageDef;
}
public FabricHostDef stageDef(StageDef stageDef) {
return copy(this.hostPattern, this.isPrimary, this.isReplica, this.nodeDefs, this.laneDefs,
this.logDef, this.policyDef, stageDef, this.storeDef);
}
@Override
public final StoreDef storeDef() {
return this.storeDef;
}
public FabricHostDef storeDef(StoreDef storeDef) {
return copy(this.hostPattern, this.isPrimary, this.isReplica, this.nodeDefs, this.laneDefs,
this.logDef, this.policyDef, this.stageDef, storeDef);
}
protected FabricHostDef copy(UriPattern hostPattern, boolean isPrimary, boolean isReplica,
UriMapper<NodeDef> nodeDefs, UriMapper<LaneDef> laneDefs,
LogDef logDef, PolicyDef policyDef, StageDef stageDef,
StoreDef storeDef) {
return new FabricHostDef(hostPattern, isPrimary, isReplica, nodeDefs, laneDefs,
logDef, policyDef, stageDef, storeDef);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof FabricHostDef) {
final FabricHostDef that = (FabricHostDef) other;
return this.hostPattern.equals(that.hostPattern)
&& this.isPrimary == that.isPrimary
&& this.isReplica == that.isReplica
&& this.nodeDefs.equals(that.nodeDefs)
&& this.laneDefs.equals(that.laneDefs)
&& (this.logDef == null ? that.logDef == null : this.logDef.equals(that.logDef))
&& (this.policyDef == null ? that.policyDef == null : this.policyDef.equals(that.policyDef))
&& (this.stageDef == null ? that.stageDef == null : this.stageDef.equals(that.stageDef))
&& (this.storeDef == null ? that.storeDef == null : this.storeDef.equals(that.storeDef));
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(FabricHostDef.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(
Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(hashSeed, this.hostPattern.hashCode()),
Murmur3.hash(this.isPrimary)), Murmur3.hash(this.isReplica)), this.nodeDefs.hashCode()),
this.laneDefs.hashCode()), Murmur3.hash(this.logDef)), Murmur3.hash(this.policyDef)),
Murmur3.hash(this.stageDef)), Murmur3.hash(this.storeDef)));
}
@Override
public void debug(Output<?> output) {
output = output.write("FabricHostDef").write('.');
if (this.hostPattern.isUri()) {
output = output.write("fromHostUri").write('(').debug(this.hostPattern.toUri()).write(')');
} else {
output = output.write("fromHostPattern").write('(').debug(this.hostPattern).write(')');
}
if (this.isPrimary) {
output = output.write('.').write("isPrimary").write('(').debug(this.isPrimary).write(')');
}
if (this.isReplica) {
output = output.write('.').write("isReplica").write('(').debug(this.isReplica).write(')');
}
for (NodeDef nodeDef : this.nodeDefs.values()) {
output = output.write('.').write("nodeDef").write('(').debug(nodeDef).write(')');
}
for (LaneDef laneDef : this.laneDefs.values()) {
output = output.write('.').write("laneDef").write('(').debug(laneDef).write(')');
}
if (this.logDef != null) {
output = output.write('.').write("logDef").write('(').debug(this.logDef).write(')');
}
if (this.policyDef != null) {
output = output.write('.').write("policyDef").write('(').debug(this.policyDef).write(')');
}
if (this.stageDef != null) {
output = output.write('.').write("stageDef").write('(').debug(this.stageDef).write(')');
}
if (this.storeDef != null) {
output = output.write('.').write("storeDef").write('(').debug(this.storeDef).write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
public static FabricHostDef fromHostUri(Uri hostUri) {
return new FabricHostDef(UriPattern.from(hostUri), false, false, UriMapper.empty(),
UriMapper.empty(), null, null, null, null);
}
public static FabricHostDef fromHostUri(String hostUri) {
return fromHostUri(Uri.parse(hostUri));
}
public static FabricHostDef fromHostPattern(UriPattern hostPattern) {
return new FabricHostDef(hostPattern, false, false, UriMapper.empty(),
UriMapper.empty(), null, null, null, null);
}
public static FabricHostDef fromHostPattern(String hostPattern) {
return fromHostPattern(UriPattern.parse(hostPattern));
}
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricIdentity.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.fabric;
import swim.api.auth.Identity;
import swim.api.store.Store;
import swim.structure.Value;
import swim.uri.Uri;
public class FabricIdentity implements Identity {
final Uri requestUri;
final Uri fromUri;
final Value subject;
public FabricIdentity(Uri requestUri, Uri fromUri, Value subject) {
this.requestUri = requestUri;
this.fromUri = fromUri;
this.subject = subject;
}
@Override
public boolean isAuthenticated() {
return true;
}
@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-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricKernel.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.fabric;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import swim.api.agent.AgentDef;
import swim.api.auth.Authenticator;
import swim.api.auth.AuthenticatorDef;
import swim.api.plane.PlaneDef;
import swim.api.plane.PlaneException;
import swim.api.plane.PlaneFactory;
import swim.api.space.Space;
import swim.api.space.SpaceDef;
import swim.collections.FingerTrieSeq;
import swim.collections.HashTrieMap;
import swim.concurrent.StageDef;
import swim.kernel.KernelContext;
import swim.kernel.KernelProxy;
import swim.runtime.HostDef;
import swim.runtime.LaneDef;
import swim.runtime.LogDef;
import swim.runtime.MeshDef;
import swim.runtime.NodeDef;
import swim.runtime.PartDef;
import swim.runtime.PartPredicate;
import swim.runtime.PolicyDef;
import swim.store.StoreDef;
import swim.structure.Item;
import swim.structure.Value;
import swim.uri.Uri;
import swim.uri.UriMapper;
import swim.uri.UriPattern;
public class FabricKernel extends KernelProxy {
final double kernelPriority;
volatile HashTrieMap<String, Fabric> fabrics;
public FabricKernel(double kernelPriority) {
this.kernelPriority = kernelPriority;
this.fabrics = HashTrieMap.empty();
}
public FabricKernel() {
this(KERNEL_PRIORITY);
}
@Override
public final double kernelPriority() {
return this.kernelPriority;
}
@Override
public SpaceDef defineSpace(Item spaceConfig) {
final SpaceDef fabricDef = defineFabricSpace(spaceConfig);
return fabricDef != null ? fabricDef : super.defineSpace(spaceConfig);
}
public FabricDef defineFabricSpace(Item spaceConfig) {
final Value value = spaceConfig.toValue();
final Value header = value.getAttr("fabric");
if (header.isDefined()) {
final String fabricProvider = header.get("provider").stringValue(null);
if (fabricProvider == null || FabricKernel.class.getName().equals(fabricProvider)) {
final KernelContext kernel = kernelWrapper().unwrapKernel(KernelContext.class);
final String spaceName = spaceConfig.key().stringValue(null);
FingerTrieSeq<PlaneDef> planeDefs = FingerTrieSeq.empty();
HashTrieMap<String, AuthenticatorDef> authenticatorDefs = HashTrieMap.empty();
HashTrieMap<Uri, MeshDef> meshDefs = HashTrieMap.empty();
HashTrieMap<Value, PartDef> partDefs = HashTrieMap.empty();
UriMapper<HostDef> hostDefs = UriMapper.empty();
UriMapper<NodeDef> nodeDefs = UriMapper.empty();
UriMapper<LaneDef> laneDefs = UriMapper.empty();
LogDef logDef = null;
PolicyDef policyDef = null;
StageDef stageDef = null;
StoreDef storeDef = null;
for (int i = 0, n = value.length(); i < n; i += 1) {
final Item item = value.getItem(i);
final PlaneDef planeDef = kernel.definePlane(item);
if (planeDef != null) {
planeDefs = planeDefs.appended(planeDef);
continue;
}
final AuthenticatorDef authenticatorDef = kernel.defineAuthenticator(item);
if (authenticatorDef != null) {
authenticatorDefs = authenticatorDefs.updated(authenticatorDef.authenticatorName(), authenticatorDef);
continue;
}
final MeshDef meshDef = kernel.defineMesh(item);
if (meshDef != null) {
meshDefs = meshDefs.updated(meshDef.meshUri(), meshDef);
continue;
}
final PartDef partDef = kernel.definePart(item);
if (partDef != null) {
partDefs = partDefs.updated(partDef.partKey(), partDef);
continue;
}
final HostDef hostDef = kernel.defineHost(item);
if (hostDef != null) {
hostDefs = hostDefs.updated(hostDef.hostPattern(), hostDef);
continue;
}
final NodeDef nodeDef = kernel.defineNode(item);
if (nodeDef != null) {
nodeDefs = nodeDefs.updated(nodeDef.nodePattern(), nodeDef);
continue;
}
final LaneDef laneDef = kernel.defineLane(item);
if (laneDef != null) {
laneDefs = laneDefs.updated(laneDef.lanePattern(), laneDef);
continue;
}
final LogDef newLogDef = kernel.defineLog(item);
if (newLogDef != null) {
logDef = newLogDef;
continue;
}
final PolicyDef newPolicyDef = kernel.definePolicy(item);
if (newPolicyDef != null) {
policyDef = newPolicyDef;
continue;
}
final StageDef newStageDef = kernel.defineStage(item);
if (newStageDef != null) {
stageDef = newStageDef;
continue;
}
final StoreDef newStoreDef = kernel.defineStore(item);
if (newStoreDef != null) {
storeDef = newStoreDef;
continue;
}
}
return new FabricDef(spaceName, planeDefs, authenticatorDefs, meshDefs,
partDefs, hostDefs, nodeDefs, laneDefs,
logDef, policyDef, stageDef, storeDef);
}
}
return null;
}
@Override
public Space openSpace(SpaceDef spaceDef) {
if (spaceDef instanceof FabricDef) {
return openFabric((FabricDef) spaceDef);
} else {
return super.openSpace(spaceDef);
}
}
public Fabric openFabric(FabricDef fabricDef) {
final String spaceName = fabricDef.spaceName;
Fabric fabric = null;
do {
final HashTrieMap<String, Fabric> oldFabrics = this.fabrics;
final Fabric oldFabric = oldFabrics.get(spaceName);
if (oldFabric == null) {
if (fabric == null) {
fabric = createFabric(spaceName, fabricDef);
}
final HashTrieMap<String, Fabric> newFabrics = oldFabrics.updated(spaceName, fabric);
if (FABRICS.compareAndSet(this, oldFabrics, newFabrics)) {
if (isStarted()) {
fabric.start();
}
break;
}
} else {
fabric = oldFabric;
break;
}
} while (true);
return fabric;
}
protected Fabric createFabric(String spaceName, FabricDef spaceDef) {
final KernelContext kernel = kernelWrapper().unwrapKernel(KernelContext.class);
final Fabric fabric = new Fabric(spaceName, spaceDef, kernel);
createAuthenticators(fabric, spaceDef);
createPlanes(fabric, spaceDef);
return fabric;
}
protected void createAuthenticators(Fabric fabric, FabricDef spaceDef) {
for (AuthenticatorDef authenticatorDef : spaceDef.authenticatorDefs()) {
if (fabric.getAuthenticator(authenticatorDef.authenticatorName()) == null) {
createAuthenticator(fabric, authenticatorDef);
}
}
}
protected void createAuthenticator(Fabric fabric, AuthenticatorDef authenticatorDef) {
final KernelContext kernel = kernelWrapper().unwrapKernel(KernelContext.class);
Authenticator authenticator = kernel.createAuthenticator(authenticatorDef, null);
if (authenticator != null) {
authenticator = kernel.injectAuthenticator(authenticator);
}
if (authenticator != null) {
fabric.addAuthenticator(authenticatorDef.authenticatorName(), authenticator);
}
}
protected void createPlanes(Fabric fabric, FabricDef spaceDef) {
for (PlaneDef planeDef : spaceDef.planeDefs()) {
if (fabric.getPlane(planeDef.planeName()) == null) {
createPlane(fabric, planeDef);
}
}
}
protected void createPlane(Fabric fabric, PlaneDef planeDef) {
final KernelContext kernel = kernelWrapper().unwrapKernel(KernelContext.class);
final PlaneFactory<?> planeFactory = kernel.createPlaneFactory(planeDef, null);
if (planeFactory != null) {
fabric.openPlane(planeDef.planeName(), planeFactory);
} else {
throw new PlaneException("No factory for plane: " + planeDef.planeName());
}
}
@Override
public Space getSpace(String spaceName) {
Space space = getFabric(spaceName);
if (space == null) {
space = super.getSpace(spaceName);
}
return space;
}
public Fabric getFabric(String spaceName) {
return this.fabrics.get(spaceName);
}
@Override
public MeshDef defineMesh(Item meshConfig) {
final MeshDef meshDef = defineFabricMesh(meshConfig);
return meshDef != null ? meshDef : super.defineMesh(meshConfig);
}
public FabricMeshDef defineFabricMesh(Item meshConfig) {
final Value value = meshConfig.toValue();
final Value header = value.getAttr("mesh");
if (header.isDefined()) {
final String fabricProvider = header.get("provider").stringValue(null);
if (fabricProvider == null || FabricKernel.class.getName().equals(fabricProvider)) {
final KernelContext kernel = kernelWrapper().unwrapKernel(KernelContext.class);
Uri meshUri = Uri.empty();
HashTrieMap<Value, PartDef> partDefs = HashTrieMap.empty();
UriMapper<HostDef> hostDefs = UriMapper.empty();
UriMapper<NodeDef> nodeDefs = UriMapper.empty();
UriMapper<LaneDef> laneDefs = UriMapper.empty();
LogDef logDef = null;
PolicyDef policyDef = null;
StageDef stageDef = null;
StoreDef storeDef = null;
for (int i = 0, n = value.length(); i < n; i += 1) {
final Item item = value.getItem(i);
if (item.keyEquals("uri")) {
meshUri = item.toValue().cast(Uri.form(), meshUri);
continue;
}
final PartDef partDef = kernel.definePart(item);
if (partDef != null) {
partDefs = partDefs.updated(partDef.partKey(), partDef);
continue;
}
final HostDef hostDef = kernel.defineHost(item);
if (hostDef != null) {
hostDefs = hostDefs.updated(hostDef.hostPattern(), hostDef);
continue;
}
final NodeDef nodeDef = kernel.defineNode(item);
if (nodeDef != null) {
nodeDefs = nodeDefs.updated(nodeDef.nodePattern(), nodeDef);
continue;
}
final LaneDef laneDef = kernel.defineLane(item);
if (laneDef != null) {
laneDefs = laneDefs.updated(laneDef.lanePattern(), laneDef);
continue;
}
final LogDef newLogDef = kernel.defineLog(item);
if (newLogDef != null) {
logDef = newLogDef;
continue;
}
final PolicyDef newPolicyDef = kernel.definePolicy(item);
if (newPolicyDef != null) {
policyDef = newPolicyDef;
continue;
}
final StageDef newStageDef = kernel.defineStage(item);
if (newStageDef != null) {
stageDef = newStageDef;
continue;
}
final StoreDef newStoreDef = kernel.defineStore(item);
if (newStoreDef != null) {
storeDef = newStoreDef;
continue;
}
}
return new FabricMeshDef(meshUri, partDefs, hostDefs, nodeDefs, laneDefs,
logDef, policyDef, stageDef, storeDef);
}
}
return null;
}
@Override
public PartDef definePart(Item partConfig) {
final PartDef partDef = defineFabricPart(partConfig);
return partDef != null ? partDef : super.definePart(partConfig);
}
public FabricPartDef defineFabricPart(Item partConfig) {
final Value value = partConfig.toValue();
final Value header = value.getAttr("part");
if (header.isDefined()) {
final String fabricProvider = header.get("provider").stringValue(null);
if (fabricProvider == null || FabricKernel.class.getName().equals(fabricProvider)) {
final KernelContext kernel = kernelWrapper().unwrapKernel(KernelContext.class);
Value partKey = null;
PartPredicate predicate = null;
boolean isGateway = false;
UriMapper<HostDef> hostDefs = UriMapper.empty();
UriMapper<NodeDef> nodeDefs = UriMapper.empty();
UriMapper<LaneDef> laneDefs = UriMapper.empty();
LogDef logDef = null;
PolicyDef policyDef = null;
StageDef stageDef = null;
StoreDef storeDef = null;
for (int i = 0, n = value.length(); i < n; i += 1) {
final Item item = value.getItem(i);
if (item.keyEquals("key")) {
partKey = item.toValue();
continue;
}
if (item.keyEquals("predicate")) {
predicate = PartPredicate.fromValue(item.toValue());
continue;
}
if (item.keyEquals("isGateway")) {
isGateway = item.toValue().booleanValue(isGateway);
continue;
}
final HostDef hostDef = kernel.defineHost(item);
if (hostDef != null) {
hostDefs = hostDefs.updated(hostDef.hostPattern(), hostDef);
continue;
}
final NodeDef nodeDef = kernel.defineNode(item);
if (nodeDef != null) {
nodeDefs = nodeDefs.updated(nodeDef.nodePattern(), nodeDef);
continue;
}
final LaneDef laneDef = kernel.defineLane(item);
if (laneDef != null) {
laneDefs = laneDefs.updated(laneDef.lanePattern(), laneDef);
continue;
}
final LogDef newLogDef = kernel.defineLog(item);
if (newLogDef != null) {
logDef = newLogDef;
continue;
}
final PolicyDef newPolicyDef = kernel.definePolicy(item);
if (newPolicyDef != null) {
policyDef = newPolicyDef;
continue;
}
final StageDef newStageDef = kernel.defineStage(item);
if (newStageDef != null) {
stageDef = newStageDef;
continue;
}
final StoreDef newStoreDef = kernel.defineStore(item);
if (newStoreDef != null) {
storeDef = newStoreDef;
continue;
}
}
if (partKey != null && predicate != null) {
return new FabricPartDef(partKey, predicate, isGateway, hostDefs, nodeDefs,
laneDefs, logDef, policyDef, stageDef, storeDef);
}
}
}
return null;
}
@Override
public HostDef defineHost(Item hostConfig) {
final HostDef hostDef = defineFabricHost(hostConfig);
return hostDef != null ? hostDef : super.defineHost(hostConfig);
}
public FabricHostDef defineFabricHost(Item hostConfig) {
final Value value = hostConfig.toValue();
final Value header = value.getAttr("host");
if (header.isDefined()) {
final String fabricProvider = header.get("provider").stringValue(null);
if (fabricProvider == null || FabricKernel.class.getName().equals(fabricProvider)) {
final KernelContext kernel = kernelWrapper().unwrapKernel(KernelContext.class);
UriPattern hostPattern = UriPattern.empty();
boolean isPrimary = false;
boolean isReplica = false;
UriMapper<NodeDef> nodeDefs = UriMapper.empty();
UriMapper<LaneDef> laneDefs = UriMapper.empty();
LogDef logDef = null;
PolicyDef policyDef = null;
StageDef stageDef = null;
StoreDef storeDef = null;
for (int i = 0, n = value.length(); i < n; i += 1) {
final Item item = value.getItem(i);
if (item.keyEquals("uri") || item.keyEquals("pattern")) {
hostPattern = item.toValue().cast(UriPattern.form(), hostPattern);
continue;
}
if (item.keyEquals("primary") || item.keyEquals("isPrimary")) {
isPrimary = item.toValue().booleanValue(isPrimary);
continue;
}
if (item.keyEquals("replica") || item.keyEquals("isReplica")) {
isReplica = item.toValue().booleanValue(isReplica);
continue;
}
final NodeDef nodeDef = kernel.defineNode(item);
if (nodeDef != null) {
nodeDefs = nodeDefs.updated(nodeDef.nodePattern(), nodeDef);
continue;
}
final LaneDef laneDef = kernel.defineLane(item);
if (laneDef != null) {
laneDefs = laneDefs.updated(laneDef.lanePattern(), laneDef);
continue;
}
final LogDef newLogDef = kernel.defineLog(item);
if (newLogDef != null) {
logDef = newLogDef;
continue;
}
final PolicyDef newPolicyDef = kernel.definePolicy(item);
if (newPolicyDef != null) {
policyDef = newPolicyDef;
continue;
}
final StageDef newStageDef = kernel.defineStage(item);
if (newStageDef != null) {
stageDef = newStageDef;
continue;
}
final StoreDef newStoreDef = kernel.defineStore(item);
if (newStoreDef != null) {
storeDef = newStoreDef;
continue;
}
}
return new FabricHostDef(hostPattern, isPrimary, isReplica, nodeDefs,
laneDefs, logDef, policyDef, stageDef, storeDef);
}
}
return null;
}
@Override
public NodeDef defineNode(Item nodeConfig) {
final NodeDef nodeDef = defineFabricNode(nodeConfig);
return nodeDef != null ? nodeDef : super.defineNode(nodeConfig);
}
public FabricNodeDef defineFabricNode(Item nodeConfig) {
final Value value = nodeConfig.toValue();
final Value header = value.getAttr("node");
if (header.isDefined()) {
final String fabricProvider = header.get("provider").stringValue(null);
if (fabricProvider == null || FabricKernel.class.getName().equals(fabricProvider)) {
final KernelContext kernel = kernelWrapper().unwrapKernel(KernelContext.class);
UriPattern nodePattern = null;
FingerTrieSeq<AgentDef> agentDefs = FingerTrieSeq.empty();
UriMapper<LaneDef> laneDefs = UriMapper.empty();
LogDef logDef = null;
PolicyDef policyDef = null;
StageDef stageDef = null;
StoreDef storeDef = null;
for (int i = 0, n = value.length(); i < n; i += 1) {
final Item item = value.getItem(i);
if (item.keyEquals("uri") || item.keyEquals("pattern")) {
nodePattern = item.toValue().cast(UriPattern.form(), nodePattern);
continue;
}
final AgentDef agentDef = kernel.defineAgent(item);
if (agentDef != null) {
agentDefs = agentDefs.appended(agentDef);
continue;
}
final LaneDef laneDef = kernel.defineLane(item);
if (laneDef != null) {
laneDefs = laneDefs.updated(laneDef.lanePattern(), laneDef);
continue;
}
final LogDef newLogDef = kernel.defineLog(item);
if (newLogDef != null) {
logDef = newLogDef;
continue;
}
final PolicyDef newPolicyDef = kernel.definePolicy(item);
if (newPolicyDef != null) {
policyDef = newPolicyDef;
continue;
}
final StageDef newStageDef = kernel.defineStage(item);
if (newStageDef != null) {
stageDef = newStageDef;
continue;
}
final StoreDef newStoreDef = kernel.defineStore(item);
if (newStoreDef != null) {
storeDef = newStoreDef;
continue;
}
}
if (nodePattern != null) {
return new FabricNodeDef(nodePattern, agentDefs, laneDefs,
logDef, policyDef, stageDef, storeDef);
}
}
}
return null;
}
@Override
public LaneDef defineLane(Item laneConfig) {
final LaneDef laneDef = defineFabricLane(laneConfig);
return laneDef != null ? laneDef : super.defineLane(laneConfig);
}
public FabricLaneDef defineFabricLane(Item laneConfig) {
final Value value = laneConfig.toValue();
final Value header = value.getAttr("lane");
if (header.isDefined()) {
final String fabricProvider = header.get("provider").stringValue(null);
if (fabricProvider == null || FabricKernel.class.getName().equals(fabricProvider)) {
final KernelContext kernel = kernelWrapper().unwrapKernel(KernelContext.class);
final String laneType = header.get("type").stringValue(null);
UriPattern lanePattern = null;
LogDef logDef = null;
PolicyDef policyDef = null;
StageDef stageDef = null;
StoreDef storeDef = null;
for (int i = 0, n = value.length(); i < n; i += 1) {
final Item item = value.getItem(i);
if (item.keyEquals("uri") || item.keyEquals("pattern")) {
lanePattern = item.toValue().cast(UriPattern.form(), lanePattern);
continue;
}
final LogDef newLogDef = kernel.defineLog(item);
if (newLogDef != null) {
logDef = newLogDef;
continue;
}
final PolicyDef newPolicyDef = kernel.definePolicy(item);
if (newPolicyDef != null) {
policyDef = newPolicyDef;
continue;
}
final StageDef newStageDef = kernel.defineStage(item);
if (newStageDef != null) {
stageDef = newStageDef;
continue;
}
final StoreDef newStoreDef = kernel.defineStore(item);
if (newStoreDef != null) {
storeDef = newStoreDef;
continue;
}
}
if (lanePattern != null) {
return new FabricLaneDef(lanePattern, laneType, logDef, policyDef, stageDef, storeDef);
}
}
}
return null;
}
@Override
public void didStart() {
for (Fabric fabric : this.fabrics.values()) {
fabric.start();
}
}
@Override
public void willStop() {
for (Fabric fabric : this.fabrics.values()) {
fabric.stop();
}
}
private static final double KERNEL_PRIORITY = 1.0;
@SuppressWarnings("unchecked")
static final AtomicReferenceFieldUpdater<FabricKernel, HashTrieMap<String, Fabric>> FABRICS =
AtomicReferenceFieldUpdater.newUpdater(FabricKernel.class, (Class<HashTrieMap<String, Fabric>>) (Class<?>) HashTrieMap.class, "fabrics");
public static FabricKernel fromValue(Value moduleConfig) {
final Value header = moduleConfig.getAttr("kernel");
final String kernelClassName = header.get("class").stringValue(null);
if (kernelClassName == null || FabricKernel.class.getName().equals(kernelClassName)) {
final double kernelPriority = header.get("priority").doubleValue(KERNEL_PRIORITY);
return new FabricKernel(kernelPriority);
}
return null;
}
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricLane.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.fabric;
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.Stage;
import swim.concurrent.StageDef;
import swim.runtime.CellBinding;
import swim.runtime.CellContext;
import swim.runtime.LaneBinding;
import swim.runtime.LaneContext;
import swim.runtime.LaneDef;
import swim.runtime.LinkBinding;
import swim.runtime.LinkContext;
import swim.runtime.LogDef;
import swim.runtime.NodeBinding;
import swim.runtime.PolicyDef;
import swim.store.StoreBinding;
import swim.store.StoreDef;
import swim.structure.Value;
import swim.uri.Uri;
import swim.util.Log;
import swim.warp.CommandMessage;
public class FabricLane extends FabricTier implements LaneBinding, LaneContext {
final LaneBinding laneBinding;
LaneContext laneContext;
LaneDef laneDef;
public FabricLane(LaneBinding laneBinding, LaneDef laneDef) {
this.laneBinding = laneBinding;
this.laneDef = laneDef;
}
public final LaneDef laneDef() {
return this.laneDef;
}
public final FabricNode fabricNode() {
return node().unwrapNode(FabricNode.class);
}
@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 final CellBinding cellBinding() {
return this.laneBinding;
}
@Override
public final CellContext cellContext() {
return this.laneContext;
}
@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 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);
}
public Log createLog(LogDef logDef) {
final FabricNode node = fabricNode();
return node != null ? node.createLog(logDef) : null;
}
public Log injectLog(Log log) {
final FabricNode node = fabricNode();
return node != null ? node.injectLog(log) : log;
}
@Override
protected Log openLog() {
Log log;
if (this.laneDef != null && this.laneDef.logDef() != null) {
log = createLog(this.laneDef.logDef());
} else {
log = openLaneLog();
}
if (log != null) {
log = injectLog(log);
}
return log;
}
public Policy createPolicy(PolicyDef policyDef) {
final FabricNode node = fabricNode();
return node != null ? node.createPolicy(policyDef) : null;
}
public Policy injectPolicy(Policy policy) {
final FabricNode node = fabricNode();
return node != null ? node.injectPolicy(policy) : policy;
}
@Override
protected Policy openPolicy() {
Policy policy;
if (this.laneDef != null && this.laneDef.policyDef() != null) {
policy = createPolicy(this.laneDef.policyDef());
} else {
policy = openLanePolicy();
}
if (policy != null) {
policy = injectPolicy(policy);
}
return policy;
}
public Stage createStage(StageDef stageDef) {
final FabricNode node = fabricNode();
return node != null ? node.createStage(stageDef) : null;
}
public Stage injectStage(Stage stage) {
final FabricNode node = fabricNode();
return node != null ? node.injectStage(stage) : stage;
}
@Override
protected Stage openStage() {
Stage stage;
if (this.laneDef != null && this.laneDef.stageDef() != null) {
stage = createStage(this.laneDef.stageDef());
} else {
stage = openLaneStage();
}
if (stage != null) {
stage = injectStage(stage);
}
return stage;
}
public StoreBinding createStore(StoreDef storeDef) {
final FabricNode node = fabricNode();
return node != null ? node.createStore(storeDef) : null;
}
public StoreBinding injectStore(StoreBinding store) {
final FabricNode node = fabricNode();
return node != null ? node.injectStore(store) : store;
}
@Override
protected StoreBinding openStore() {
StoreBinding store = null;
if (this.laneDef != null && this.laneDef.storeDef() != null) {
store = createStore(this.laneDef.storeDef());
} else {
store = openLaneStore();
}
if (store != null) {
store = injectStore(store);
}
return store;
}
protected Log openLaneLog() {
final FabricNode node = fabricNode();
return node != null ? node.openLaneLog(laneUri()) : null;
}
protected Policy openLanePolicy() {
final FabricNode node = fabricNode();
return node != null ? node.openLanePolicy(laneUri()) : null;
}
protected Stage openLaneStage() {
final FabricNode node = fabricNode();
return node != null ? node.openLaneStage(laneUri()) : null;
}
protected StoreBinding openLaneStore() {
final FabricNode node = fabricNode();
return node != null ? node.openLaneStore(laneUri()) : null;
}
@Override
public void didClose() {
this.laneBinding.didClose();
}
@Override
public void didFail(Throwable error) {
this.laneBinding.didFail(error);
}
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricLaneDef.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.fabric;
import swim.codec.Debug;
import swim.codec.Format;
import swim.codec.Output;
import swim.concurrent.StageDef;
import swim.runtime.LaneDef;
import swim.runtime.LogDef;
import swim.runtime.PolicyDef;
import swim.store.StoreDef;
import swim.uri.Uri;
import swim.uri.UriPattern;
import swim.util.Murmur3;
public class FabricLaneDef implements LaneDef, Debug {
final UriPattern lanePattern;
final String laneType;
final LogDef logDef;
final PolicyDef policyDef;
final StageDef stageDef;
final StoreDef storeDef;
public FabricLaneDef(UriPattern lanePattern, String laneType, LogDef logDef,
PolicyDef policyDef, StageDef stageDef, StoreDef storeDef) {
this.lanePattern = lanePattern;
this.laneType = laneType;
this.logDef = logDef;
this.policyDef = policyDef;
this.stageDef = stageDef;
this.storeDef = storeDef;
}
@Override
public final Uri laneUri() {
return this.lanePattern.isUri() ? this.lanePattern.toUri() : null;
}
@Override
public final UriPattern lanePattern() {
return this.lanePattern;
}
public FabricLaneDef lanePattern(UriPattern lanePattern) {
return copy(lanePattern, this.laneType, this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final String laneType() {
return this.laneType;
}
public FabricLaneDef laneType(String laneType) {
return copy(this.lanePattern, laneType, this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final LogDef logDef() {
return this.logDef;
}
public FabricLaneDef logDef(LogDef logDef) {
return copy(this.lanePattern, this.laneType, logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final PolicyDef policyDef() {
return this.policyDef;
}
public FabricLaneDef policyDef(PolicyDef policyDef) {
return copy(this.lanePattern, this.laneType, this.logDef, policyDef, this.stageDef, this.storeDef);
}
@Override
public final StageDef stageDef() {
return this.stageDef;
}
public FabricLaneDef stageDef(StageDef stageDef) {
return copy(this.lanePattern, this.laneType, this.logDef, this.policyDef, stageDef, this.storeDef);
}
@Override
public final StoreDef storeDef() {
return this.storeDef;
}
public FabricLaneDef storeDef(StoreDef storeDef) {
return copy(this.lanePattern, this.laneType, this.logDef, this.policyDef, this.stageDef, storeDef);
}
protected FabricLaneDef copy(UriPattern lanePattern, String laneType, LogDef logDef,
PolicyDef policyDef, StageDef stageDef, StoreDef storeDef) {
return new FabricLaneDef(lanePattern, laneType, logDef, policyDef, stageDef, storeDef);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof FabricLaneDef) {
final FabricLaneDef that = (FabricLaneDef) other;
return this.lanePattern.equals(that.lanePattern)
&& (this.laneType == null ? that.laneType == null : this.laneType.equals(that.laneType))
&& (this.logDef == null ? that.logDef == null : this.logDef.equals(that.logDef))
&& (this.policyDef == null ? that.policyDef == null : this.policyDef.equals(that.policyDef))
&& (this.stageDef == null ? that.stageDef == null : this.stageDef.equals(that.stageDef))
&& (this.storeDef == null ? that.storeDef == null : this.storeDef.equals(that.storeDef));
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(FabricLaneDef.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(
Murmur3.mix(hashSeed, this.lanePattern.hashCode()), Murmur3.hash(this.laneType)),
Murmur3.hash(this.logDef)), Murmur3.hash(this.policyDef)),
Murmur3.hash(this.stageDef)), Murmur3.hash(this.storeDef)));
}
@Override
public void debug(Output<?> output) {
output = output.write("FabricLaneDef").write('.');
if (this.lanePattern.isUri()) {
output = output.write("fromLaneUri").write('(').debug(this.lanePattern.toUri()).write(')');
} else {
output = output.write("fromLanePattern").write('(').debug(this.lanePattern).write(')');
}
if (this.laneType != null) {
output = output.write('.').write("laneType").write('(').debug(this.laneType).write(')');
}
if (this.logDef != null) {
output = output.write('.').write("logDef").write('(').debug(this.logDef).write(')');
}
if (this.policyDef != null) {
output = output.write('.').write("policyDef").write('(').debug(this.policyDef).write(')');
}
if (this.stageDef != null) {
output = output.write('.').write("stageDef").write('(').debug(this.stageDef).write(')');
}
if (this.storeDef != null) {
output = output.write('.').write("storeDef").write('(').debug(this.storeDef).write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
public static FabricLaneDef fromLaneUri(Uri laneUri) {
return new FabricLaneDef(UriPattern.from(laneUri), null, null, null, null, null);
}
public static FabricLaneDef fromLaneUri(String laneUri) {
return fromLaneUri(Uri.parse(laneUri));
}
public static FabricLaneDef fromLanePattern(UriPattern lanePattern) {
return new FabricLaneDef(lanePattern, null, null, null, null, null);
}
public static FabricLaneDef fromLanePattern(String lanePattern) {
return fromLanePattern(UriPattern.parse(lanePattern));
}
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricMesh.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.fabric;
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.Stage;
import swim.concurrent.StageDef;
import swim.runtime.CellBinding;
import swim.runtime.CellContext;
import swim.runtime.EdgeBinding;
import swim.runtime.HostBinding;
import swim.runtime.HostDef;
import swim.runtime.LaneBinding;
import swim.runtime.LaneDef;
import swim.runtime.LogDef;
import swim.runtime.MeshBinding;
import swim.runtime.MeshContext;
import swim.runtime.MeshDef;
import swim.runtime.NodeBinding;
import swim.runtime.NodeDef;
import swim.runtime.PartBinding;
import swim.runtime.PartDef;
import swim.runtime.PolicyDef;
import swim.runtime.agent.AgentModel;
import swim.store.StoreBinding;
import swim.store.StoreDef;
import swim.structure.Value;
import swim.uri.Uri;
import swim.util.Log;
public class FabricMesh extends FabricTier implements MeshBinding, MeshContext {
final MeshBinding meshBinding;
MeshContext meshContext;
MeshDef meshDef;
public FabricMesh(MeshBinding meshBinding, MeshDef meshDef) {
this.meshBinding = meshBinding;
this.meshDef = meshDef;
}
public final MeshDef meshDef() {
return this.meshDef;
}
public final Fabric fabricEdge() {
return edge().unwrapEdge(Fabric.class);
}
@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 final CellBinding cellBinding() {
return this.meshBinding;
}
@Override
public final CellContext cellContext() {
return this.meshContext;
}
@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);
}
public Log createLog(LogDef logDef) {
final Fabric edge = fabricEdge();
return edge != null ? edge.createLog(logDef) : null;
}
public Log injectLog(Log log) {
final Fabric edge = fabricEdge();
return edge != null ? edge.injectLog(log) : log;
}
@Override
protected Log openLog() {
Log log;
if (this.meshDef != null && this.meshDef.logDef() != null) {
log = createLog(this.meshDef.logDef());
} else {
log = openMeshLog();
}
if (log != null) {
log = injectLog(log);
}
return log;
}
public Policy createPolicy(PolicyDef policyDef) {
final Fabric edge = fabricEdge();
return edge != null ? edge.createPolicy(policyDef) : null;
}
public Policy injectPolicy(Policy policy) {
final Fabric edge = fabricEdge();
return edge != null ? edge.injectPolicy(policy) : policy;
}
@Override
protected Policy openPolicy() {
Policy policy;
if (this.meshDef != null && this.meshDef.policyDef() != null) {
policy = createPolicy(this.meshDef.policyDef());
} else {
policy = openMeshPolicy();
}
if (policy != null) {
policy = injectPolicy(policy);
}
return policy;
}
public Stage createStage(StageDef stageDef) {
final Fabric edge = fabricEdge();
return edge != null ? edge.createStage(stageDef) : null;
}
public Stage injectStage(Stage stage) {
final Fabric edge = fabricEdge();
return edge != null ? edge.injectStage(stage) : stage;
}
@Override
protected Stage openStage() {
Stage stage;
if (this.meshDef != null && this.meshDef.stageDef() != null) {
stage = createStage(this.meshDef.stageDef());
} else {
stage = openMeshStage();
}
if (stage != null) {
stage = injectStage(stage);
}
return stage;
}
public StoreBinding createStore(StoreDef storeDef) {
final Fabric edge = fabricEdge();
return edge != null ? edge.createStore(storeDef) : null;
}
public StoreBinding injectStore(StoreBinding store) {
final Fabric edge = fabricEdge();
return edge != null ? edge.injectStore(store) : store;
}
@Override
protected StoreBinding openStore() {
StoreBinding store = null;
if (this.meshDef != null && this.meshDef.storeDef() != null) {
store = createStore(this.meshDef.storeDef());
} else {
store = openMeshStore();
}
if (store != null) {
store = injectStore(store);
}
return store;
}
protected Log openMeshLog() {
final Fabric edge = fabricEdge();
return edge != null ? edge.openMeshLog(meshUri()) : null;
}
protected Policy openMeshPolicy() {
final Fabric edge = fabricEdge();
return edge != null ? edge.openMeshPolicy(meshUri()) : null;
}
protected Stage openMeshStage() {
final Fabric edge = fabricEdge();
return edge != null ? edge.openMeshStage(meshUri()) : null;
}
protected StoreBinding openMeshStore() {
final Fabric edge = fabricEdge();
return edge != null ? edge.openMeshStore(meshUri()) : null;
}
public PartDef getPartDef(Value partKey) {
final MeshDef meshDef = this.meshDef;
PartDef partDef = meshDef != null ? meshDef.getPartDef(partKey) : null;
if (partDef == null) {
final Fabric edge = fabricEdge();
partDef = edge != null ? edge.getPartDef(meshUri(), partKey) : null;
}
return partDef;
}
@Override
public PartBinding createPart(Value partKey) {
return this.meshContext.createPart(partKey);
}
@Override
public PartBinding injectPart(Value partKey, PartBinding part) {
final PartDef partDef = getPartDef(partKey);
return new FabricPart(this.meshContext.injectPart(partKey, part), partDef);
}
public Log openPartLog(Value partKey) {
final Fabric edge = fabricEdge();
return edge != null ? edge.openPartLog(meshUri(), partKey) : null;
}
public Policy openPartPolicy(Value partKey) {
final Fabric edge = fabricEdge();
return edge != null ? edge.openPartPolicy(meshUri(), partKey) : null;
}
public Stage openPartStage(Value partKey) {
final Fabric edge = fabricEdge();
return edge != null ? edge.openPartStage(meshUri(), partKey) : null;
}
public StoreBinding openPartStore(Value partKey) {
final Fabric edge = fabricEdge();
return edge != null ? edge.openPartStore(meshUri(), partKey) : null;
}
public HostDef getHostDef(Value partKey, Uri hostUri) {
final MeshDef meshDef = this.meshDef;
HostDef hostDef = meshDef != null ? meshDef.getHostDef(hostUri) : null;
if (hostDef == null) {
final Fabric edge = fabricEdge();
hostDef = edge != null ? edge.getHostDef(meshUri(), partKey, hostUri) : null;
}
return hostDef;
}
@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);
}
public Log openHostLog(Value partKey, Uri hostUri) {
final Fabric edge = fabricEdge();
return edge != null ? edge.openHostLog(meshUri(), partKey, hostUri) : null;
}
public Policy openHostPolicy(Value partKey, Uri hostUri) {
final Fabric edge = fabricEdge();
return edge != null ? edge.openHostPolicy(meshUri(), partKey, hostUri) : null;
}
public Stage openHostStage(Value partKey, Uri hostUri) {
final Fabric edge = fabricEdge();
return edge != null ? edge.openHostStage(meshUri(), partKey, hostUri) : null;
}
public StoreBinding openHostStore(Value partKey, Uri hostUri) {
final Fabric edge = fabricEdge();
return edge != null ? edge.openHostStore(meshUri(), partKey, hostUri) : null;
}
public NodeDef getNodeDef(Value partKey, Uri hostUri, Uri nodeUri) {
final MeshDef meshDef = this.meshDef;
NodeDef nodeDef = meshDef != null ? meshDef.getNodeDef(nodeUri) : null;
if (nodeDef == null) {
final Fabric edge = fabricEdge();
nodeDef = edge != null ? edge.getNodeDef(meshUri(), partKey, hostUri, nodeUri) : null;
}
return nodeDef;
}
@Override
public NodeBinding createNode(Value partKey, Uri hostUri, Uri nodeUri) {
NodeBinding node = this.meshContext.createNode(partKey, hostUri, nodeUri);
if (node == null && !meshUri().isDefined()) {
final MeshDef meshDef = this.meshDef;
final NodeDef nodeDef = meshDef != null ? meshDef.getNodeDef(nodeUri) : null;
if (nodeDef != null) {
final Value props = nodeDef.props(nodeUri);
node = new AgentModel(props);
}
}
return node;
}
@Override
public NodeBinding injectNode(Value partKey, Uri hostUri, Uri nodeUri, NodeBinding node) {
return this.meshContext.injectNode(partKey, hostUri, nodeUri, node);
}
public Log openNodeLog(Value partKey, Uri hostUri, Uri nodeUri) {
final Fabric edge = fabricEdge();
return edge != null ? edge.openNodeLog(meshUri(), partKey, hostUri, nodeUri) : null;
}
public Policy openNodePolicy(Value partKey, Uri hostUri, Uri nodeUri) {
final Fabric edge = fabricEdge();
return edge != null ? edge.openNodePolicy(meshUri(), partKey, hostUri, nodeUri) : null;
}
public Stage openNodeStage(Value partKey, Uri hostUri, Uri nodeUri) {
final Fabric edge = fabricEdge();
return edge != null ? edge.openNodeStage(meshUri(), partKey, hostUri, nodeUri) : null;
}
public StoreBinding openNodeStore(Value partKey, Uri hostUri, Uri nodeUri) {
final Fabric edge = fabricEdge();
return edge != null ? edge.openNodeStore(meshUri(), partKey, hostUri, nodeUri) : null;
}
public LaneDef getLaneDef(Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri) {
final MeshDef meshDef = this.meshDef;
LaneDef laneDef = meshDef != null ? meshDef.getLaneDef(laneUri) : null;
if (laneDef == null) {
final Fabric edge = fabricEdge();
laneDef = edge != null ? edge.getLaneDef(meshUri(), partKey, hostUri, nodeUri, laneUri) : null;
}
return laneDef;
}
@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);
}
public Log openLaneLog(Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri) {
final Fabric edge = fabricEdge();
return edge != null ? edge.openLaneLog(meshUri(), partKey, hostUri, nodeUri, laneUri) : null;
}
public Policy openLanePolicy(Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri) {
final Fabric edge = fabricEdge();
return edge != null ? edge.openLanePolicy(meshUri(), partKey, hostUri, nodeUri, laneUri) : null;
}
public Stage openLaneStage(Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri) {
final Fabric edge = fabricEdge();
return edge != null ? edge.openLaneStage(meshUri(), partKey, hostUri, nodeUri, laneUri) : null;
}
public StoreBinding openLaneStore(Value partKey, Uri hostUri, Uri nodeUri, Uri laneUri) {
final Fabric edge = fabricEdge();
return edge != null ? edge.openLaneStore(meshUri(), partKey, hostUri, nodeUri, laneUri) : null;
}
@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);
if (!meshUri().isDefined()) {
final MeshDef meshDef = this.meshDef;
final NodeDef nodeDef = meshDef != null ? meshDef.getNodeDef(nodeUri) : null;
if (nodeDef != null && node instanceof AgentModel) {
final AgentModel agentModel = (AgentModel) node;
for (AgentDef agentDef : nodeDef.agentDefs()) {
final AgentFactory<?> agentFactory = createAgentFactory(partKey, hostUri, nodeUri, agentDef);
if (agentDef != null) {
Value props = agentDef.props();
if (!props.isDefined()) {
props = agentModel.props();
}
agentModel.addAgentView(agentModel.createAgent(agentFactory, props));
}
}
}
}
}
@Override
public PolicyDirective<Identity> authenticate(Credentials credentials) {
return this.meshContext.authenticate(credentials);
}
@Override
public void didClose() {
this.meshBinding.didClose();
}
@Override
public void didFail(Throwable error) {
this.meshBinding.didFail(error);
}
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricMeshDef.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.fabric;
import java.util.Collection;
import swim.codec.Debug;
import swim.codec.Format;
import swim.codec.Output;
import swim.collections.HashTrieMap;
import swim.concurrent.StageDef;
import swim.runtime.HostDef;
import swim.runtime.LaneDef;
import swim.runtime.LogDef;
import swim.runtime.MeshDef;
import swim.runtime.NodeDef;
import swim.runtime.PartDef;
import swim.runtime.PolicyDef;
import swim.store.StoreDef;
import swim.structure.Value;
import swim.uri.Uri;
import swim.uri.UriMapper;
import swim.util.Murmur3;
public class FabricMeshDef implements MeshDef, Debug {
final Uri meshUri;
final HashTrieMap<Value, PartDef> partDefs;
final UriMapper<HostDef> hostDefs;
final UriMapper<NodeDef> nodeDefs;
final UriMapper<LaneDef> laneDefs;
final LogDef logDef;
final PolicyDef policyDef;
final StageDef stageDef;
final StoreDef storeDef;
public FabricMeshDef(Uri meshUri, HashTrieMap<Value, PartDef> partDefs,
UriMapper<HostDef> hostDefs, UriMapper<NodeDef> nodeDefs,
UriMapper<LaneDef> laneDefs, LogDef logDef, PolicyDef policyDef,
StageDef stageDef, StoreDef storeDef) {
this.meshUri = meshUri;
this.partDefs = partDefs;
this.hostDefs = hostDefs;
this.nodeDefs = nodeDefs;
this.laneDefs = laneDefs;
this.logDef = logDef;
this.policyDef = policyDef;
this.stageDef = stageDef;
this.storeDef = storeDef;
}
@Override
public final Uri meshUri() {
return this.meshUri;
}
public FabricMeshDef meshUri(Uri meshUri) {
return copy(meshUri, this.partDefs, this.hostDefs, this.nodeDefs, this.laneDefs,
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends PartDef> partDefs() {
return this.partDefs.values();
}
@Override
public final PartDef getPartDef(Value partKey) {
return this.partDefs.get(partKey);
}
public FabricMeshDef partDef(PartDef partDef) {
return copy(this.meshUri, this.partDefs.updated(partDef.partKey(), partDef),
this.hostDefs, this.nodeDefs, this.laneDefs,
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends HostDef> hostDefs() {
return this.hostDefs.values();
}
@Override
public final HostDef getHostDef(Uri hostUri) {
return this.hostDefs.get(hostUri);
}
public FabricMeshDef hostDef(HostDef hostDef) {
return copy(this.meshUri, this.partDefs, this.hostDefs.updated(hostDef.hostPattern(), hostDef),
this.nodeDefs, this.laneDefs,
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends NodeDef> nodeDefs() {
return this.nodeDefs.values();
}
@Override
public final NodeDef getNodeDef(Uri nodeUri) {
return this.nodeDefs.get(nodeUri);
}
public FabricMeshDef nodeDef(NodeDef nodeDef) {
return copy(this.meshUri, this.partDefs, this.hostDefs,
this.nodeDefs.updated(nodeDef.nodePattern(), nodeDef), this.laneDefs,
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends LaneDef> laneDefs() {
return this.laneDefs.values();
}
@Override
public final LaneDef getLaneDef(Uri laneUri) {
return this.laneDefs.get(laneUri);
}
public FabricMeshDef laneDef(LaneDef laneDef) {
return copy(this.meshUri, this.partDefs, this.hostDefs, this.nodeDefs,
this.laneDefs.updated(laneDef.lanePattern(), laneDef),
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final LogDef logDef() {
return this.logDef;
}
public FabricMeshDef logDef(LogDef logDef) {
return copy(this.meshUri, this.partDefs, this.hostDefs, this.nodeDefs, this.laneDefs,
logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final PolicyDef policyDef() {
return this.policyDef;
}
public FabricMeshDef policyDef(PolicyDef policyDef) {
return copy(this.meshUri, this.partDefs, this.hostDefs, this.nodeDefs, this.laneDefs,
this.logDef, policyDef, this.stageDef, this.storeDef);
}
@Override
public final StageDef stageDef() {
return this.stageDef;
}
public FabricMeshDef stageDef(StageDef stageDef) {
return copy(this.meshUri, this.partDefs, this.hostDefs, this.nodeDefs, this.laneDefs,
this.logDef, this.policyDef, stageDef, this.storeDef);
}
@Override
public final StoreDef storeDef() {
return this.storeDef;
}
public FabricMeshDef storeDef(StoreDef storeDef) {
return copy(this.meshUri, this.partDefs, this.hostDefs, this.nodeDefs, this.laneDefs,
this.logDef, this.policyDef, this.stageDef, storeDef);
}
protected FabricMeshDef copy(Uri meshUri, HashTrieMap<Value, PartDef> partDefs,
UriMapper<HostDef> hostDefs, UriMapper<NodeDef> nodeDefs,
UriMapper<LaneDef> laneDefs, LogDef logDef, PolicyDef policyDef,
StageDef stageDef, StoreDef storeDef) {
return new FabricMeshDef(meshUri, partDefs, hostDefs, nodeDefs, laneDefs,
logDef, policyDef, stageDef, storeDef);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof FabricMeshDef) {
final FabricMeshDef that = (FabricMeshDef) other;
return this.meshUri.equals(that.meshUri)
&& this.partDefs.equals(that.partDefs)
&& this.hostDefs.equals(that.hostDefs)
&& this.nodeDefs.equals(that.nodeDefs)
&& this.laneDefs.equals(that.laneDefs)
&& (this.logDef == null ? that.logDef == null : this.logDef.equals(that.logDef))
&& (this.policyDef == null ? that.policyDef == null : this.policyDef.equals(that.policyDef))
&& (this.stageDef == null ? that.stageDef == null : this.stageDef.equals(that.stageDef))
&& (this.storeDef == null ? that.storeDef == null : this.storeDef.equals(that.storeDef));
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(FabricMeshDef.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(
Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(hashSeed, Murmur3.hash(this.meshUri)),
this.partDefs.hashCode()), this.hostDefs.hashCode()), this.nodeDefs.hashCode()),
this.laneDefs.hashCode()), Murmur3.hash(this.logDef)), Murmur3.hash(this.policyDef)),
Murmur3.hash(this.stageDef)), Murmur3.hash(this.storeDef)));
}
@Override
public void debug(Output<?> output) {
output = output.write("FabricMeshDef").write('.').write("fromMeshUri").write('(')
.debug(this.meshUri).write(')');
for (PartDef partDef : this.partDefs.values()) {
output = output.write('.').write("partDef").write('(').debug(partDef).write(')');
}
for (HostDef hostDef : this.hostDefs.values()) {
output = output.write('.').write("hostDef").write('(').debug(hostDef).write(')');
}
for (NodeDef nodeDef : this.nodeDefs.values()) {
output = output.write('.').write("nodeDef").write('(').debug(nodeDef).write(')');
}
for (LaneDef laneDef : this.laneDefs.values()) {
output = output.write('.').write("laneDef").write('(').debug(laneDef).write(')');
}
if (this.logDef != null) {
output = output.write('.').write("logDef").write('(').debug(this.logDef).write(')');
}
if (this.policyDef != null) {
output = output.write('.').write("policyDef").write('(').debug(this.policyDef).write(')');
}
if (this.stageDef != null) {
output = output.write('.').write("stageDef").write('(').debug(this.stageDef).write(')');
}
if (this.storeDef != null) {
output = output.write('.').write("storeDef").write('(').debug(this.storeDef).write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
public static FabricMeshDef fromMeshUri(Uri meshUri) {
return new FabricMeshDef(meshUri, HashTrieMap.empty(), UriMapper.empty(),
UriMapper.empty(), UriMapper.empty(),
null, null, null, null);
}
public static FabricMeshDef fromMeshUri(String meshUri) {
return fromMeshUri(Uri.parse(meshUri));
}
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricNode.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.fabric;
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.Stage;
import swim.concurrent.StageDef;
import swim.runtime.CellBinding;
import swim.runtime.CellContext;
import swim.runtime.HostBinding;
import swim.runtime.LaneBinding;
import swim.runtime.LaneDef;
import swim.runtime.LogDef;
import swim.runtime.NodeBinding;
import swim.runtime.NodeContext;
import swim.runtime.NodeDef;
import swim.runtime.PolicyDef;
import swim.store.StoreBinding;
import swim.store.StoreDef;
import swim.structure.Record;
import swim.structure.Value;
import swim.uri.Uri;
import swim.util.Log;
public class FabricNode extends FabricTier implements NodeBinding, NodeContext {
final NodeBinding nodeBinding;
NodeContext nodeContext;
NodeDef nodeDef;
public FabricNode(NodeBinding nodeBinding, NodeDef nodeDef) {
this.nodeBinding = nodeBinding;
this.nodeDef = nodeDef;
}
public final NodeDef nodeDef() {
return this.nodeDef;
}
public final FabricHost fabricHost() {
return host().unwrapHost(FabricHost.class);
}
@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 final CellBinding cellBinding() {
return this.nodeBinding;
}
@Override
public final CellContext cellContext() {
return this.nodeContext;
}
@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 HashTrieMap<Uri, LaneBinding> lanes() {
return this.nodeBinding.lanes();
}
@Override
public LaneBinding getLane(Uri laneUri) {
return this.nodeBinding.getLane(laneUri);
}
public Log createLog(LogDef logDef) {
final FabricHost host = fabricHost();
return host != null ? host.createLog(logDef) : null;
}
public Log injectLog(Log log) {
final FabricHost host = fabricHost();
return host != null ? host.injectLog(log) : log;
}
@Override
protected Log openLog() {
Log log;
if (this.nodeDef != null && this.nodeDef.logDef() != null) {
log = createLog(this.nodeDef.logDef());
} else {
log = openNodeLog();
}
if (log != null) {
log = injectLog(log);
}
return log;
}
public Policy createPolicy(PolicyDef policyDef) {
final FabricHost host = fabricHost();
return host != null ? host.createPolicy(policyDef) : null;
}
public Policy injectPolicy(Policy policy) {
final FabricHost host = fabricHost();
return host != null ? host.injectPolicy(policy) : policy;
}
@Override
protected Policy openPolicy() {
Policy policy;
if (this.nodeDef != null && this.nodeDef.policyDef() != null) {
policy = createPolicy(this.nodeDef.policyDef());
} else {
policy = openNodePolicy();
}
if (policy != null) {
policy = injectPolicy(policy);
}
return policy;
}
public Stage createStage(StageDef stageDef) {
final FabricHost host = fabricHost();
return host != null ? host.createStage(stageDef) : null;
}
public Stage injectStage(Stage stage) {
final FabricHost host = fabricHost();
return host != null ? host.injectStage(stage) : stage;
}
@Override
protected Stage openStage() {
Stage stage;
if (this.nodeDef != null && this.nodeDef.stageDef() != null) {
stage = createStage(this.nodeDef.stageDef());
} else {
stage = openNodeStage();
}
if (stage != null) {
stage = injectStage(stage);
}
return stage;
}
public StoreBinding createStore(StoreDef storeDef) {
final FabricHost host = fabricHost();
return host != null ? host.createStore(storeDef) : null;
}
public StoreBinding injectStore(StoreBinding store) {
final FabricHost host = fabricHost();
return host != null ? host.injectStore(store) : store;
}
@Override
protected StoreBinding openStore() {
StoreBinding store = null;
if (this.nodeDef != null && this.nodeDef.storeDef() != null) {
store = createStore(this.nodeDef.storeDef());
} else {
store = openNodeStore();
}
if (store == null) {
final StoreBinding hostStore = host().hostContext().store();
if (hostStore != null) {
store = hostStore.storeContext().openStore(Record.create(1).slot("node", nodeUri().toString()));
}
}
if (store != null) {
store = injectStore(store);
}
return store;
}
protected Log openNodeLog() {
final FabricHost host = fabricHost();
return host != null ? host.openNodeLog(nodeUri()) : null;
}
protected Policy openNodePolicy() {
final FabricHost host = fabricHost();
return host != null ? host.openNodePolicy(nodeUri()) : null;
}
protected Stage openNodeStage() {
final FabricHost host = fabricHost();
return host != null ? host.openNodeStage(nodeUri()) : null;
}
protected StoreBinding openNodeStore() {
final FabricHost host = fabricHost();
return host != null ? host.openNodeStore(nodeUri()) : null;
}
@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);
}
public LaneDef getLaneDef(Uri laneUri) {
final NodeDef nodeDef = this.nodeDef;
LaneDef laneDef = nodeDef != null ? nodeDef.getLaneDef(laneUri) : null;
if (laneDef == null) {
final FabricHost host = fabricHost();
laneDef = host != null ? host.getLaneDef(nodeUri(), laneUri) : null;
}
return laneDef;
}
@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) {
final LaneDef laneDef = getLaneDef(laneUri);
return new FabricLane(this.nodeContext.injectLane(laneUri, lane), laneDef);
}
@Override
public void openLanes(NodeBinding node) {
this.nodeContext.openLanes(node);
final NodeDef nodeDef = this.nodeDef;
if (nodeDef != null) {
for (LaneDef laneDef : nodeDef.laneDefs()) {
final Uri laneUri = laneDef.laneUri();
final LaneBinding lane = createLane(laneDef);
if (laneDef != null) {
node.openLane(laneUri, lane);
}
}
}
}
public Log openLaneLog(Uri laneUri) {
final FabricHost host = fabricHost();
return host != null ? host.openLaneLog(nodeUri(), laneUri) : null;
}
public Policy openLanePolicy(Uri laneUri) {
final FabricHost host = fabricHost();
return host != null ? host.openLanePolicy(nodeUri(), laneUri) : null;
}
public Stage openLaneStage(Uri laneUri) {
final FabricHost host = fabricHost();
return host != null ? host.openLaneStage(nodeUri(), laneUri) : null;
}
public StoreBinding openLaneStore(Uri laneUri) {
final FabricHost host = fabricHost();
return host != null ? host.openLaneStore(nodeUri(), laneUri) : null;
}
@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 void didClose() {
this.nodeBinding.didClose();
}
@Override
public void didFail(Throwable error) {
this.nodeBinding.didFail(error);
}
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricNodeDef.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.fabric;
import java.util.Collection;
import swim.api.agent.AgentDef;
import swim.codec.Debug;
import swim.codec.Format;
import swim.codec.Output;
import swim.collections.FingerTrieSeq;
import swim.concurrent.StageDef;
import swim.runtime.LaneDef;
import swim.runtime.LogDef;
import swim.runtime.NodeDef;
import swim.runtime.PolicyDef;
import swim.store.StoreDef;
import swim.uri.Uri;
import swim.uri.UriMapper;
import swim.uri.UriPattern;
import swim.util.Murmur3;
public class FabricNodeDef implements NodeDef, Debug {
final UriPattern nodePattern;
final FingerTrieSeq<AgentDef> agentDefs;
final UriMapper<LaneDef> laneDefs;
final LogDef logDef;
final PolicyDef policyDef;
final StageDef stageDef;
final StoreDef storeDef;
public FabricNodeDef(UriPattern nodePattern, FingerTrieSeq<AgentDef> agentDefs,
UriMapper<LaneDef> laneDefs, LogDef logDef, PolicyDef policyDef,
StageDef stageDef, StoreDef storeDef) {
this.nodePattern = nodePattern;
this.agentDefs = agentDefs;
this.laneDefs = laneDefs;
this.logDef = logDef;
this.policyDef = policyDef;
this.stageDef = stageDef;
this.storeDef = storeDef;
}
@Override
public final Uri nodeUri() {
return this.nodePattern.isUri() ? this.nodePattern.toUri() : null;
}
@Override
public final UriPattern nodePattern() {
return this.nodePattern;
}
public FabricNodeDef nodePattern(UriPattern nodePattern) {
return copy(nodePattern, this.agentDefs, this.laneDefs,
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends AgentDef> agentDefs() {
return this.agentDefs;
}
@Override
public final AgentDef getAgentDef(String agentName) {
for (AgentDef agentDef : this.agentDefs) {
if (agentName.equals(agentDef.agentName())) {
return agentDef;
}
}
return null;
}
public FabricNodeDef agentDef(AgentDef agentDef) {
return copy(this.nodePattern, this.agentDefs.appended(agentDef), this.laneDefs,
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends LaneDef> laneDefs() {
return this.laneDefs.values();
}
@Override
public final LaneDef getLaneDef(Uri laneUri) {
return this.laneDefs.get(laneUri);
}
public FabricNodeDef laneDef(LaneDef laneDef) {
return copy(this.nodePattern, this.agentDefs, this.laneDefs.updated(laneDef.lanePattern(), laneDef),
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final LogDef logDef() {
return this.logDef;
}
public FabricNodeDef logDef(LogDef logDef) {
return copy(this.nodePattern, this.agentDefs, this.laneDefs,
logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final PolicyDef policyDef() {
return this.policyDef;
}
public FabricNodeDef policyDef(PolicyDef policyDef) {
return copy(this.nodePattern, this.agentDefs, this.laneDefs,
this.logDef, policyDef, this.stageDef, this.storeDef);
}
@Override
public final StageDef stageDef() {
return this.stageDef;
}
public FabricNodeDef stageDef(StageDef stageDef) {
return copy(this.nodePattern, this.agentDefs, this.laneDefs,
this.logDef, this.policyDef, stageDef, this.storeDef);
}
@Override
public final StoreDef storeDef() {
return this.storeDef;
}
public FabricNodeDef storeDef(StoreDef storeDef) {
return copy(this.nodePattern, this.agentDefs, this.laneDefs,
this.logDef, this.policyDef, this.stageDef, storeDef);
}
protected FabricNodeDef copy(UriPattern nodePattern, FingerTrieSeq<AgentDef> agentDefs,
UriMapper<LaneDef> laneDefs, LogDef logDef, PolicyDef policyDef,
StageDef stageDef, StoreDef storeDef) {
return new FabricNodeDef(nodePattern, agentDefs, laneDefs,
logDef, policyDef, stageDef, storeDef);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof FabricNodeDef) {
final FabricNodeDef that = (FabricNodeDef) other;
return this.nodePattern.equals(that.nodePattern)
&& this.agentDefs.equals(that.agentDefs)
&& this.laneDefs.equals(that.laneDefs)
&& (this.logDef == null ? that.logDef == null : this.logDef.equals(that.logDef))
&& (this.policyDef == null ? that.policyDef == null : this.policyDef.equals(that.policyDef))
&& (this.stageDef == null ? that.stageDef == null : this.stageDef.equals(that.stageDef))
&& (this.storeDef == null ? that.storeDef == null : this.storeDef.equals(that.storeDef));
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(FabricNodeDef.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(
Murmur3.mix(hashSeed, this.nodePattern.hashCode()), this.agentDefs.hashCode()),
this.laneDefs.hashCode()), Murmur3.hash(this.logDef)), Murmur3.hash(this.policyDef)),
Murmur3.hash(this.stageDef)), Murmur3.hash(this.storeDef)));
}
@Override
public void debug(Output<?> output) {
output = output.write("FabricNodeDef").write('.');
if (this.nodePattern.isUri()) {
output = output.write("fromNodeUri").write('(').debug(this.nodePattern.toUri()).write(')');
} else {
output = output.write("fromNodePattern").write('(').debug(this.nodePattern).write(')');
}
for (AgentDef agentDef : this.agentDefs()) {
output = output.write('.').write("agentDef").write('(').debug(agentDef).write(')');
}
for (LaneDef laneDef : this.laneDefs.values()) {
output = output.write('.').write("laneDef").write('(').debug(laneDef).write(')');
}
if (this.logDef != null) {
output = output.write('.').write("logDef").write('(').debug(this.logDef).write(')');
}
if (this.policyDef != null) {
output = output.write('.').write("policyDef").write('(').debug(this.policyDef).write(')');
}
if (this.stageDef != null) {
output = output.write('.').write("stageDef").write('(').debug(this.stageDef).write(')');
}
if (this.storeDef != null) {
output = output.write('.').write("storeDef").write('(').debug(this.storeDef).write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
public static FabricNodeDef fromNodeUri(Uri nodeUri) {
return new FabricNodeDef(UriPattern.from(nodeUri), FingerTrieSeq.empty(),
UriMapper.empty(), null, null, null, null);
}
public static FabricNodeDef fromNodeUri(String nodeUri) {
return fromNodeUri(Uri.parse(nodeUri));
}
public static FabricNodeDef fromNodePattern(UriPattern nodePattern) {
return new FabricNodeDef(nodePattern, FingerTrieSeq.empty(),
UriMapper.empty(), null, null, null, null);
}
public static FabricNodeDef fromNodePattern(String nodePattern) {
return fromNodePattern(UriPattern.parse(nodePattern));
}
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricPart.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.fabric;
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.Stage;
import swim.concurrent.StageDef;
import swim.runtime.CellBinding;
import swim.runtime.CellContext;
import swim.runtime.HostBinding;
import swim.runtime.HostDef;
import swim.runtime.LaneBinding;
import swim.runtime.LaneDef;
import swim.runtime.LogDef;
import swim.runtime.MeshBinding;
import swim.runtime.NodeBinding;
import swim.runtime.NodeDef;
import swim.runtime.PartBinding;
import swim.runtime.PartContext;
import swim.runtime.PartDef;
import swim.runtime.PartPredicate;
import swim.runtime.PolicyDef;
import swim.runtime.agent.AgentModel;
import swim.store.StoreBinding;
import swim.store.StoreDef;
import swim.structure.Value;
import swim.uri.Uri;
import swim.util.Log;
public class FabricPart extends FabricTier implements PartBinding, PartContext {
final PartBinding partBinding;
PartContext partContext;
PartDef partDef;
public FabricPart(PartBinding partBinding, PartDef partDef) {
this.partBinding = partBinding;
this.partDef = partDef;
}
public final PartDef partDef() {
return this.partDef;
}
public final FabricMesh fabricMesh() {
return mesh().unwrapMesh(FabricMesh.class);
}
@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 final CellBinding cellBinding() {
return this.partBinding;
}
@Override
public final CellContext cellContext() {
return this.partContext;
}
@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();
}
public Log createLog(LogDef logDef) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.createLog(logDef) : null;
}
public Log injectLog(Log log) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.injectLog(log) : log;
}
@Override
protected Log openLog() {
Log log;
if (this.partDef != null && this.partDef.logDef() != null) {
log = createLog(this.partDef.logDef());
} else {
log = openPartLog();
}
if (log != null) {
log = injectLog(log);
}
return log;
}
public Policy createPolicy(PolicyDef policyDef) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.createPolicy(policyDef) : null;
}
public Policy injectPolicy(Policy policy) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.injectPolicy(policy) : policy;
}
@Override
protected Policy openPolicy() {
Policy policy;
if (this.partDef != null && this.partDef.policyDef() != null) {
policy = createPolicy(this.partDef.policyDef());
} else {
policy = openPartPolicy();
}
if (policy != null) {
policy = injectPolicy(policy);
}
return policy;
}
public Stage createStage(StageDef stageDef) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.createStage(stageDef) : null;
}
public Stage injectStage(Stage stage) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.injectStage(stage) : stage;
}
@Override
protected Stage openStage() {
Stage stage;
if (this.partDef != null && this.partDef.stageDef() != null) {
stage = createStage(this.partDef.stageDef());
} else {
stage = openPartStage();
}
if (stage != null) {
stage = injectStage(stage);
}
return stage;
}
public StoreBinding createStore(StoreDef storeDef) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.createStore(storeDef) : null;
}
public StoreBinding injectStore(StoreBinding store) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.injectStore(store) : store;
}
@Override
protected StoreBinding openStore() {
StoreBinding store = null;
if (this.partDef != null && this.partDef.storeDef() != null) {
store = createStore(this.partDef.storeDef());
} else {
store = openPartStore();
}
if (store != null) {
store = injectStore(store);
}
return store;
}
protected Log openPartLog() {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.openPartLog(partKey()) : null;
}
protected Policy openPartPolicy() {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.openPartPolicy(partKey()) : null;
}
protected Stage openPartStage() {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.openPartStage(partKey()) : null;
}
protected StoreBinding openPartStore() {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.openPartStore(partKey()) : null;
}
public HostDef getHostDef(Uri hostUri) {
final PartDef partDef = this.partDef;
HostDef hostDef = partDef != null ? partDef.getHostDef(hostUri) : null;
if (hostDef == null) {
final FabricMesh mesh = fabricMesh();
hostDef = mesh != null ? mesh.getHostDef(partKey(), hostUri) : null;
}
return hostDef;
}
@Override
public HostBinding createHost(Uri hostUri) {
return this.partContext.createHost(hostUri);
}
@Override
public HostBinding injectHost(Uri hostUri, HostBinding host) {
final HostDef hostDef = getHostDef(hostUri);
return new FabricHost(this.partContext.injectHost(hostUri, host), hostDef);
}
public Log openHostLog(Uri hostUri) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.openHostLog(partKey(), hostUri) : null;
}
public Policy openHostPolicy(Uri hostUri) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.openHostPolicy(partKey(), hostUri) : null;
}
public Stage openHostStage(Uri hostUri) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.openHostStage(partKey(), hostUri) : null;
}
public StoreBinding openHostStore(Uri hostUri) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.openHostStore(partKey(), hostUri) : null;
}
public NodeDef getNodeDef(Uri hostUri, Uri nodeUri) {
final PartDef partDef = this.partDef;
NodeDef nodeDef = partDef != null ? partDef.getNodeDef(nodeUri) : null;
if (nodeDef == null) {
final FabricMesh mesh = fabricMesh();
nodeDef = mesh != null ? mesh.getNodeDef(partKey(), hostUri, nodeUri) : null;
}
return nodeDef;
}
@Override
public NodeBinding createNode(Uri hostUri, Uri nodeUri) {
NodeBinding node = this.partContext.createNode(hostUri, nodeUri);
if (node == null && !meshUri().isDefined()) {
final PartDef partDef = this.partDef;
final NodeDef nodeDef = partDef != null ? partDef.getNodeDef(nodeUri) : null;
if (nodeDef != null) {
final Value props = nodeDef.props(nodeUri);
node = new AgentModel(props);
}
}
return node;
}
@Override
public NodeBinding injectNode(Uri hostUri, Uri nodeUri, NodeBinding node) {
return this.partContext.injectNode(hostUri, nodeUri, node);
}
public Log openNodeLog(Uri hostUri, Uri nodeUri) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.openNodeLog(partKey(), hostUri, nodeUri) : null;
}
public Policy openNodePolicy(Uri hostUri, Uri nodeUri) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.openNodePolicy(partKey(), hostUri, nodeUri) : null;
}
public Stage openNodeStage(Uri hostUri, Uri nodeUri) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.openNodeStage(partKey(), hostUri, nodeUri) : null;
}
public StoreBinding openNodeStore(Uri hostUri, Uri nodeUri) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.openNodeStore(partKey(), hostUri, nodeUri) : null;
}
public LaneDef getLaneDef(Uri hostUri, Uri nodeUri, Uri laneUri) {
final PartDef partDef = this.partDef;
LaneDef laneDef = partDef != null ? partDef.getLaneDef(laneUri) : null;
if (laneDef == null) {
final FabricMesh mesh = fabricMesh();
laneDef = mesh != null ? mesh.getLaneDef(partKey(), hostUri, nodeUri, laneUri) : null;
}
return laneDef;
}
@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);
}
public Log openLaneLog(Uri hostUri, Uri nodeUri, Uri laneUri) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.openLaneLog(partKey(), hostUri, nodeUri, laneUri) : null;
}
public Policy openLanePolicy(Uri hostUri, Uri nodeUri, Uri laneUri) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.openLanePolicy(partKey(), hostUri, nodeUri, laneUri) : null;
}
public Stage openLaneStage(Uri hostUri, Uri nodeUri, Uri laneUri) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.openLaneStage(partKey(), hostUri, nodeUri, laneUri) : null;
}
public StoreBinding openLaneStore(Uri hostUri, Uri nodeUri, Uri laneUri) {
final FabricMesh mesh = fabricMesh();
return mesh != null ? mesh.openLaneStore(partKey(), hostUri, nodeUri, laneUri) : null;
}
@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);
if (!meshUri().isDefined()) {
final PartDef partDef = this.partDef;
final NodeDef nodeDef = partDef != null ? partDef.getNodeDef(nodeUri) : null;
if (nodeDef != null && node instanceof AgentModel) {
final AgentModel agentModel = (AgentModel) node;
for (AgentDef agentDef : nodeDef.agentDefs()) {
final AgentFactory<?> agentFactory = createAgentFactory(hostUri, nodeUri, agentDef);
if (agentDef != null) {
Value props = agentDef.props();
if (!props.isDefined()) {
props = agentModel.props();
}
agentModel.addAgentView(agentModel.createAgent(agentFactory, props));
}
}
}
}
}
@Override
public PolicyDirective<Identity> authenticate(Credentials credentials) {
return this.partContext.authenticate(credentials);
}
@Override
public void didClose() {
this.partBinding.didClose();
}
@Override
public void didFail(Throwable error) {
this.partBinding.didFail(error);
}
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricPartDef.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.fabric;
import java.util.Collection;
import swim.codec.Debug;
import swim.codec.Format;
import swim.codec.Output;
import swim.concurrent.StageDef;
import swim.runtime.HostDef;
import swim.runtime.LaneDef;
import swim.runtime.LogDef;
import swim.runtime.NodeDef;
import swim.runtime.PartDef;
import swim.runtime.PartPredicate;
import swim.runtime.PolicyDef;
import swim.store.StoreDef;
import swim.structure.Value;
import swim.uri.Uri;
import swim.uri.UriMapper;
import swim.util.Murmur3;
public class FabricPartDef implements PartDef, Debug {
final Value partKey;
final PartPredicate predicate;
final boolean isGateway;
final UriMapper<HostDef> hostDefs;
final UriMapper<NodeDef> nodeDefs;
final UriMapper<LaneDef> laneDefs;
final LogDef logDef;
final PolicyDef policyDef;
final StageDef stageDef;
final StoreDef storeDef;
public FabricPartDef(Value partKey, PartPredicate predicate, boolean isGateway,
UriMapper<HostDef> hostDefs, UriMapper<NodeDef> nodeDefs,
UriMapper<LaneDef> laneDefs, LogDef logDef, PolicyDef policyDef,
StageDef stageDef, StoreDef storeDef) {
this.partKey = partKey;
this.predicate = predicate;
this.isGateway = isGateway;
this.hostDefs = hostDefs;
this.nodeDefs = nodeDefs;
this.laneDefs = laneDefs;
this.logDef = logDef;
this.policyDef = policyDef;
this.stageDef = stageDef;
this.storeDef = storeDef;
}
@Override
public final Value partKey() {
return this.partKey;
}
public FabricPartDef partKey(Value partKey) {
return copy(partKey, this.predicate, this.isGateway, this.hostDefs, this.nodeDefs,
this.laneDefs, this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final PartPredicate predicate() {
return this.predicate;
}
public FabricPartDef predicate(PartPredicate predicate) {
return copy(this.partKey, predicate, this.isGateway, this.hostDefs, this.nodeDefs,
this.laneDefs, this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final boolean isGateway() {
return this.isGateway;
}
public FabricPartDef isGateway(boolean isGateway) {
return copy(this.partKey, this.predicate, isGateway, this.hostDefs, this.nodeDefs,
this.laneDefs, this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends HostDef> hostDefs() {
return this.hostDefs.values();
}
@Override
public final HostDef getHostDef(Uri hostUri) {
return this.hostDefs.get(hostUri);
}
public FabricPartDef hostDef(HostDef hostDef) {
return copy(this.partKey, this.predicate, this.isGateway,
this.hostDefs.updated(hostDef.hostPattern(), hostDef), this.nodeDefs,
this.laneDefs, this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends NodeDef> nodeDefs() {
return this.nodeDefs.values();
}
@Override
public final NodeDef getNodeDef(Uri nodeUri) {
return this.nodeDefs.get(nodeUri);
}
public FabricPartDef nodeDef(NodeDef nodeDef) {
return copy(this.partKey, this.predicate, this.isGateway, this.hostDefs,
this.nodeDefs.updated(nodeDef.nodePattern(), nodeDef), this.laneDefs,
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final Collection<? extends LaneDef> laneDefs() {
return this.laneDefs.values();
}
@Override
public final LaneDef getLaneDef(Uri laneUri) {
return this.laneDefs.get(laneUri);
}
public FabricPartDef laneDef(LaneDef laneDef) {
return copy(this.partKey, this.predicate, this.isGateway, this.hostDefs,
this.nodeDefs, this.laneDefs.updated(laneDef.lanePattern(), laneDef),
this.logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final LogDef logDef() {
return this.logDef;
}
public FabricPartDef logDef(LogDef logDef) {
return copy(this.partKey, this.predicate, this.isGateway, this.hostDefs, this.nodeDefs,
this.laneDefs, logDef, this.policyDef, this.stageDef, this.storeDef);
}
@Override
public final PolicyDef policyDef() {
return this.policyDef;
}
public FabricPartDef policyDef(PolicyDef policyDef) {
return copy(this.partKey, this.predicate, this.isGateway, this.hostDefs, this.nodeDefs,
this.laneDefs, this.logDef, policyDef, this.stageDef, this.storeDef);
}
@Override
public final StageDef stageDef() {
return this.stageDef;
}
public FabricPartDef stageDef(StageDef stageDef) {
return copy(this.partKey, this.predicate, this.isGateway, this.hostDefs, this.nodeDefs,
this.laneDefs, this.logDef, this.policyDef, stageDef, this.storeDef);
}
@Override
public final StoreDef storeDef() {
return this.storeDef;
}
public FabricPartDef storeDef(StoreDef storeDef) {
return copy(this.partKey, this.predicate, this.isGateway, this.hostDefs, this.nodeDefs,
this.laneDefs, this.logDef, this.policyDef, this.stageDef, storeDef);
}
protected FabricPartDef copy(Value partKey, PartPredicate predicate, boolean isGateway,
UriMapper<HostDef> hostDefs, UriMapper<NodeDef> nodeDefs,
UriMapper<LaneDef> laneDefs, LogDef logDef, PolicyDef policyDef,
StageDef stageDef, StoreDef storeDef) {
return new FabricPartDef(partKey, predicate, isGateway, hostDefs, nodeDefs,
laneDefs, logDef, policyDef, stageDef, storeDef);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof FabricPartDef) {
final FabricPartDef that = (FabricPartDef) other;
return this.partKey.equals(that.partKey)
&& this.predicate.equals(that.predicate)
&& this.isGateway == that.isGateway
&& this.hostDefs.equals(that.hostDefs)
&& this.nodeDefs.equals(that.nodeDefs)
&& this.laneDefs.equals(that.laneDefs)
&& (this.logDef == null ? that.logDef == null : this.logDef.equals(that.logDef))
&& (this.policyDef == null ? that.policyDef == null : this.policyDef.equals(that.policyDef))
&& (this.stageDef == null ? that.stageDef == null : this.stageDef.equals(that.stageDef))
&& (this.storeDef == null ? that.storeDef == null : this.storeDef.equals(that.storeDef));
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(FabricPartDef.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(
Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(hashSeed, Murmur3.hash(this.partKey)),
Murmur3.hash(this.predicate)), Murmur3.hash(this.isGateway)), this.hostDefs.hashCode()),
this.nodeDefs.hashCode()), this.laneDefs.hashCode()), Murmur3.hash(this.logDef)),
Murmur3.hash(this.policyDef)), Murmur3.hash(this.stageDef)), Murmur3.hash(this.storeDef)));
}
@Override
public void debug(Output<?> output) {
output = output.write("FabricPartDef").write('.').write("fromPartPredicate").write('(')
.debug(this.partKey).write(", ").debug(this.predicate).write(')');
if (this.isGateway) {
output = output.write('.').write("isGateway").write('(').debug(this.isGateway).write(')');
}
for (HostDef hostDef : this.hostDefs.values()) {
output = output.write('.').write("hostDef").write('(').debug(hostDef).write(')');
}
for (NodeDef nodeDef : this.nodeDefs.values()) {
output = output.write('.').write("nodeDef").write('(').debug(nodeDef).write(')');
}
for (LaneDef laneDef : this.laneDefs.values()) {
output = output.write('.').write("laneDef").write('(').debug(laneDef).write(')');
}
if (this.logDef != null) {
output = output.write('.').write("logDef").write('(').debug(this.logDef).write(')');
}
if (this.policyDef != null) {
output = output.write('.').write("policyDef").write('(').debug(this.policyDef).write(')');
}
if (this.stageDef != null) {
output = output.write('.').write("stageDef").write('(').debug(this.stageDef).write(')');
}
if (this.storeDef != null) {
output = output.write('.').write("storeDef").write('(').debug(this.storeDef).write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
public static FabricPartDef fromPartPredicate(Value partKey, PartPredicate predicate) {
return new FabricPartDef(partKey, predicate, false, UriMapper.empty(),
UriMapper.empty(), UriMapper.empty(),
null, null, null, null);
}
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/FabricTier.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.fabric;
import swim.concurrent.MainStage;
import swim.concurrent.Schedule;
import swim.concurrent.Stage;
import swim.runtime.TierBinding;
import swim.runtime.TierContext;
import swim.store.StoreBinding;
public abstract class FabricTier extends FabricCell implements TierBinding, TierContext {
Stage stage;
StoreBinding store;
@Override
public final TierContext tierContext() {
return this;
}
@Override
public Schedule schedule() {
final Stage stage = this.stage;
return stage != null ? stage : cellContext().schedule();
}
@Override
public Stage stage() {
final Stage stage = this.stage;
return stage != null ? stage : cellContext().stage();
}
@Override
public StoreBinding store() {
final StoreBinding store = this.store;
return store != null ? store : cellContext().store();
}
protected Stage openStage() {
return null;
}
protected void closeStage() {
final Stage stage = this.stage;
if (stage instanceof MainStage) {
((MainStage) stage).stop();
}
this.stage = null;
}
protected StoreBinding openStore() {
return null;
}
protected void closeStore() {
final StoreBinding store = this.store;
if (store != null) {
store.close();
}
this.store = null;
}
@Override
public boolean isClosed() {
return ((TierBinding) cellBinding()).isClosed();
}
@Override
public boolean isOpened() {
return ((TierBinding) cellBinding()).isOpened();
}
@Override
public boolean isLoaded() {
return ((TierBinding) cellBinding()).isLoaded();
}
@Override
public boolean isStarted() {
return ((TierBinding) cellBinding()).isStarted();
}
@Override
public void open() {
((TierBinding) cellBinding()).open();
}
@Override
public void load() {
((TierBinding) cellBinding()).load();
}
@Override
public void start() {
((TierBinding) cellBinding()).start();
}
@Override
public void stop() {
((TierBinding) cellBinding()).stop();
}
@Override
public void unload() {
((TierBinding) cellBinding()).unload();
}
@Override
public void close() {
((TierBinding) cellBinding()).close();
}
@Override
public void willOpen() {
((TierContext) cellContext()).willOpen();
if (this.log == null) {
this.log = openLog();
}
if (this.policy == null) {
this.policy = openPolicy();
}
if (this.stage == null) {
this.stage = openStage();
}
if (this.store == null) {
this.store = openStore();
}
}
@Override
public void didOpen() {
((TierContext) cellContext()).didOpen();
}
@Override
public void willLoad() {
((TierContext) cellContext()).willLoad();
}
@Override
public void didLoad() {
((TierContext) cellContext()).didLoad();
}
@Override
public void willStart() {
((TierContext) cellContext()).willStart();
}
@Override
public void didStart() {
((TierContext) cellContext()).didStart();
}
@Override
public void willStop() {
((TierContext) cellContext()).willStop();
}
@Override
public void didStop() {
((TierContext) cellContext()).didStop();
}
@Override
public void willUnload() {
((TierContext) cellContext()).willUnload();
}
@Override
public void didUnload() {
((TierContext) cellContext()).didUnload();
}
@Override
public void willClose() {
((TierContext) cellContext()).willClose();
closeStore();
closeStage();
closePolicy();
closeLog();
}
}
|
0 | java-sources/ai/swim/swim-fabric/3.10.0/swim | java-sources/ai/swim/swim-fabric/3.10.0/swim/fabric/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.
/**
* Swim fabric runtime.
*/
package swim.fabric;
|
0 | java-sources/ai/swim/swim-http | java-sources/ai/swim/swim-http/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.
/**
* HTTP wire protocol model, decoders, and encoders.
*/
module swim.http {
requires swim.util;
requires transitive swim.codec;
requires transitive swim.collections;
requires transitive swim.uri;
requires transitive swim.structure;
requires swim.recon;
requires swim.json;
requires swim.xml;
requires swim.decipher;
exports swim.http;
exports swim.http.header;
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/ChunkExtension.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.http;
import swim.codec.Debug;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.Writer;
import swim.util.Murmur3;
public final class ChunkExtension extends HttpPart implements Debug {
final String name;
final String value;
ChunkExtension(String name, String value) {
this.name = name;
this.value = value;
}
public String name() {
return this.name;
}
public String value() {
return this.value;
}
@Override
public Writer<?, ?> httpWriter(HttpWriter http) {
return http.chunkExtensionWriter(this.name, this.value);
}
@Override
public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) {
return http.writeChunkExtension(this.name, this.value, output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof ChunkExtension) {
final ChunkExtension that = (ChunkExtension) other;
return this.name.equals(that.name) && this.value.equals(that.value);
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(ChunkExtension.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed,
this.name.hashCode()), this.value.hashCode()));
}
@Override
public void debug(Output<?> output) {
output = output.write("ChunkExtension").write('.').write("from").write('(')
.debug(this.name).write(", ").write(this.value).write(')');
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
public static ChunkExtension from(String name, String value) {
return new ChunkExtension(name, value);
}
public static ChunkExtension from(String name) {
return new ChunkExtension(name, "");
}
public static ChunkExtension parseHttp(String string) {
return Http.standardParser().parseChunkExtensionString(string);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/ChunkExtensionParser.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.http;
import swim.codec.Diagnostic;
import swim.codec.Input;
import swim.codec.Parser;
final class ChunkExtensionParser extends Parser<ChunkExtension> {
final HttpParser http;
final StringBuilder name;
final StringBuilder value;
final int step;
ChunkExtensionParser(HttpParser http, StringBuilder name, StringBuilder value, int step) {
this.http = http;
this.name = name;
this.value = value;
this.step = step;
}
ChunkExtensionParser(HttpParser http) {
this(http, null, null, 1);
}
@Override
public Parser<ChunkExtension> feed(Input input) {
return parse(input, this.http, this.name, this.value, this.step);
}
static Parser<ChunkExtension> parse(Input input, HttpParser http, StringBuilder name,
StringBuilder value, 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("chunk extension", input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected("chunk extension", input));
}
}
if (step == 2) {
if (input.isCont()) {
c = input.head();
if (Http.isTokenChar(c)) {
input = input.step();
if (name == null) {
name = new StringBuilder();
}
name.appendCodePoint(c);
step = 3;
} else {
return error(Diagnostic.expected("chunk extension name", input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected("chunk extension name", input));
}
}
if (step == 3) {
while (input.isCont()) {
c = input.head();
if (Http.isTokenChar(c)) {
input = input.step();
name.appendCodePoint(c);
} else {
break;
}
}
if (!input.isEmpty()) {
step = 4;
}
}
if (step == 4) {
if (input.isCont() && input.head() == '=') {
input = input.step();
step = 5;
} else if (!input.isEmpty()) {
return done(http.chunkExtension(name.toString(), ""));
}
}
if (step == 5) {
if (input.isCont()) {
if (value == null) {
value = new StringBuilder();
}
if (input.head() == '"') {
input = input.step();
step = 8;
} else {
step = 6;
}
} else if (input.isDone()) {
return error(Diagnostic.unexpected(input));
}
}
if (step == 6) {
if (input.isCont()) {
c = input.head();
if (Http.isTokenChar(c)) {
input = input.step();
value.appendCodePoint(c);
step = 7;
} else {
return error(Diagnostic.expected("chunk extension value", input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected("chunk extension value", input));
}
}
if (step == 7) {
while (input.isCont()) {
c = input.head();
if (Http.isTokenChar(c)) {
input = input.step();
value.appendCodePoint(c);
} else {
break;
}
}
if (!input.isEmpty()) {
return done(http.chunkExtension(name.toString(), value.toString()));
}
}
do {
if (step == 8) {
while (input.isCont()) {
c = input.head();
if (Http.isQuotedChar(c)) {
input = input.step();
value.appendCodePoint(c);
} else {
break;
}
}
if (input.isCont()) {
if (c == '"') {
input = input.step();
return done(http.chunkExtension(name.toString(), value.toString()));
} else if (c == '\\') {
input = input.step();
step = 9;
} else {
return error(Diagnostic.unexpected(input));
}
} else if (input.isDone()) {
return error(Diagnostic.unexpected(input));
}
}
if (step == 9) {
if (input.isCont()) {
c = input.head();
if (Http.isEscapeChar(c)) {
input = input.step();
value.appendCodePoint(c);
step = 8;
continue;
} else {
return error(Diagnostic.expected("escape character", input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected("escape character", input));
}
}
break;
} while (true);
if (input.isError()) {
return error(input.trap());
}
return new ChunkExtensionParser(http, name, value, step);
}
static Parser<ChunkExtension> parse(Input input, HttpParser http) {
return parse(input, http, null, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/CommentParser.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.http;
import swim.codec.Diagnostic;
import swim.codec.Input;
import swim.codec.Parser;
final class CommentParser extends Parser<String> {
final StringBuilder comment;
final int level;
final int step;
CommentParser(StringBuilder comment, int level, int step) {
this.comment = comment;
this.level = level;
this.step = step;
}
@Override
public Parser<String> feed(Input input) {
return parse(input, this.comment, this.level, this.step);
}
static Parser<String> parse(Input input, StringBuilder comment, int level, int step) {
int c = 0;
if (step == 1) {
if (input.isCont() && input.head() == '(') {
input = input.step();
comment = new StringBuilder();
level = 1;
step = 2;
} else if (!input.isEmpty()) {
return done();
}
}
do {
if (step == 2) {
while (input.isCont()) {
c = input.head();
if (Http.isCommentChar(c)) {
input = input.step();
comment.appendCodePoint(c);
} else {
break;
}
}
if (input.isCont()) {
if (c == '(') {
input = input.step();
comment.append('(');
level += 1;
} else if (c == ')') {
input = input.step();
level -= 1;
if (level > 0) {
comment.append(')');
} else {
return done(comment.toString());
}
} else if (c == '\\') {
input = input.step();
step = 3;
} else {
return error(Diagnostic.unexpected(input));
}
} else if (input.isDone()) {
return error(Diagnostic.unexpected(input));
}
}
if (step == 3) {
if (input.isCont()) {
c = input.head();
if (Http.isEscapeChar(c)) {
input = input.step();
comment.appendCodePoint(c);
step = 2;
continue;
} else {
return error(Diagnostic.expected("escape character", input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected("escape character", input));
}
}
break;
} while (true);
if (input.isError()) {
return error(input.trap());
}
return new CommentParser(comment, level, step);
}
static Parser<String> parse(Input input) {
return parse(input, null, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/CommentsWriter.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.http;
import java.util.Iterator;
import swim.codec.Output;
import swim.codec.Writer;
import swim.codec.WriterException;
final class CommentsWriter extends Writer<Object, Object> {
final Iterator<String> comments;
final String comment;
final int index;
final int escape;
final int step;
CommentsWriter(Iterator<String> comments, String comment, int index, int escape, int step) {
this.comments = comments;
this.comment = comment;
this.index = index;
this.escape = escape;
this.step = step;
}
CommentsWriter(Iterator<String> comments) {
this(comments, null, 0, 0, 1);
}
@Override
public Writer<Object, Object> pull(Output<?> output) {
return write(output, this.comments, this.comment, this.index, this.escape, this.step);
}
static Writer<Object, Object> write(Output<?> output, Iterator<String> comments,
String comment, int index, int escape, int step) {
do {
if (step == 1) {
if (!comments.hasNext()) {
return done();
} else if (output.isCont()) {
output = output.write(' ');
comment = comments.next();
index = 0;
step = 2;
}
}
if (step == 2 && output.isCont()) {
output = output.write('(');
step = 3;
}
if (step == 3) {
final int length = comment.length();
while (index < length && output.isCont()) {
final int c = comment.codePointAt(index);
if (Http.isCommentChar(c)) {
output = output.write(c);
} else if (Http.isVisibleChar(c)) {
output = output.write('\\');
escape = c;
step = 4;
break;
} else {
return error(new HttpException("invalid comment: " + comment));
}
index = comment.offsetByCodePoints(index, 1);
}
if (index == length) {
comment = null;
index = 0;
step = 5;
}
}
if (step == 4 && output.isCont()) {
output = output.write(escape);
escape = 0;
step = 3;
continue;
} else if (step == 5 && output.isCont()) {
output = output.write(')');
step = 1;
continue;
}
break;
} while (true);
if (output.isDone()) {
return error(new WriterException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new CommentsWriter(comments, comment, index, escape, step);
}
public static Writer<Object, Object> write(Output<?> output, Iterator<String> comments) {
return write(output, comments, null, 0, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/ContentCoding.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.http;
import swim.codec.Debug;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.Writer;
import swim.util.Murmur3;
public final class ContentCoding extends HttpPart implements Debug {
final String name;
final float weight;
ContentCoding(String name, float weight) {
this.name = name;
this.weight = weight;
}
public String name() {
return this.name;
}
public float weight() {
return this.weight;
}
public ContentCoding weight(float weight) {
if (this.weight == weight) {
return this;
} else {
return from(this.name, weight);
}
}
public boolean isStar() {
return "*".equals(this.name);
}
public boolean isIdentity() {
return "identity".equalsIgnoreCase(this.name);
}
public boolean isCompress() {
return "compress".equalsIgnoreCase(this.name)
|| "x-compress".equalsIgnoreCase(this.name);
}
public boolean isDeflate() {
return "deflate".equalsIgnoreCase(this.name);
}
public boolean isGzip() {
return "gzip".equalsIgnoreCase(this.name)
|| "x-gzip".equalsIgnoreCase(this.name);
}
@Override
public Writer<?, ?> httpWriter(HttpWriter http) {
return http.contentCodingWriter(this.name, this.weight);
}
@Override
public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) {
return http.writeContentCoding(this.name, this.weight, output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof ContentCoding) {
final ContentCoding that = (ContentCoding) other;
return this.name.equals(that.name) && this.weight == that.weight;
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(ContentCoding.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed,
this.name.hashCode()), Murmur3.hash(this.weight)));
}
@Override
public void debug(Output<?> output) {
output = output.write("ContentCoding").write('.').write("from").write('(').debug(this.name);
if (this.weight != 1f) {
output = output.write(", ").debug(this.weight);
}
output = output.write(')');
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
private static ContentCoding star;
private static ContentCoding identity;
private static ContentCoding compress;
private static ContentCoding deflate;
private static ContentCoding gzip;
public static ContentCoding star() {
if (star == null) {
star = new ContentCoding("*", 1f);
}
return star;
}
public static ContentCoding identity() {
if (identity == null) {
identity = new ContentCoding("identity", 1f);
}
return identity;
}
public static ContentCoding compress() {
if (compress == null) {
compress = new ContentCoding("compress", 1f);
}
return compress;
}
public static ContentCoding deflate() {
if (deflate == null) {
deflate = new ContentCoding("deflate", 1f);
}
return deflate;
}
public static ContentCoding gzip() {
if (gzip == null) {
gzip = new ContentCoding("gzip", 1f);
}
return gzip;
}
public static ContentCoding from(String name, float weight) {
if (weight == 1f) {
return from(name);
} else {
return new ContentCoding(name, weight);
}
}
public static ContentCoding from(String name) {
if ("*".equals(name)) {
return star();
} else if ("identity".equals(name)) {
return identity();
} else if ("compress".equals(name)) {
return compress();
} else if ("deflate".equals(name)) {
return deflate();
} else if ("gzip".equals(name)) {
return gzip();
} else {
return new ContentCoding(name, 1f);
}
}
public static ContentCoding parse(String string) {
return Http.standardParser().parseContentCodingString(string);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/ContentCodingParser.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.http;
import swim.codec.Diagnostic;
import swim.codec.Input;
import swim.codec.Parser;
final class ContentCodingParser extends Parser<ContentCoding> {
final HttpParser http;
final StringBuilder name;
final Parser<Float> weight;
final int step;
ContentCodingParser(HttpParser http, StringBuilder name, Parser<Float> weight, int step) {
this.http = http;
this.name = name;
this.weight = weight;
this.step = step;
}
ContentCodingParser(HttpParser http) {
this(http, null, null, 1);
}
@Override
public Parser<ContentCoding> feed(Input input) {
return parse(input, this.http, this.name, this.weight, this.step);
}
static Parser<ContentCoding> parse(Input input, HttpParser http, StringBuilder name,
Parser<Float> weight, int step) {
int c = 0;
if (step == 1) {
if (input.isCont()) {
c = input.head();
if (Http.isTokenChar(c)) {
input = input.step();
if (name == null) {
name = new StringBuilder();
}
name.appendCodePoint(c);
step = 2;
} else {
return error(Diagnostic.expected("content coding", input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected("content coding", input));
}
}
if (step == 2) {
while (input.isCont()) {
c = input.head();
if (Http.isTokenChar(c)) {
input = input.step();
name.appendCodePoint(c);
} else {
break;
}
}
if (!input.isEmpty()) {
step = 3;
} else if (input.isDone()) {
return done(http.contentCoding(name.toString(), 1f));
}
}
if (step == 3) {
if (weight == null) {
weight = http.parseQValue(input);
} else {
weight = weight.feed(input);
}
if (weight.isDone()) {
final Float qvalue = weight.bind();
final float q = qvalue != null ? (float) qvalue : 1f;
return done(http.contentCoding(name.toString(), q));
} else if (weight.isError()) {
return weight.asError();
}
}
if (input.isError()) {
return error(input.trap());
}
return new ContentCodingParser(http, name, weight, step);
}
static Parser<ContentCoding> parse(Input input, HttpParser http) {
return parse(input, http, null, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/ContentCodingWriter.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.http;
import swim.codec.Output;
import swim.codec.Writer;
import swim.codec.WriterException;
final class ContentCodingWriter extends Writer<Object, Object> {
final HttpWriter http;
final String name;
final float weight;
final Writer<?, ?> part;
final int step;
ContentCodingWriter(HttpWriter http, String name, float weight, Writer<?, ?> part, int step) {
this.http = http;
this.name = name;
this.weight = weight;
this.part = part;
this.step = step;
}
ContentCodingWriter(HttpWriter http, String name, float weight) {
this(http, name, weight, null, 1);
}
@Override
public Writer<Object, Object> pull(Output<?> output) {
return write(output, this.http, this.name, this.weight, this.part, this.step);
}
static Writer<Object, Object> write(Output<?> output, HttpWriter http, String name, float weight,
Writer<?, ?> part, int step) {
if (step == 1) {
if (part == null) {
part = http.writeToken(name, output);
} else {
part = part.pull(output);
}
if (part.isDone()) {
part = null;
if (weight == 1f) {
return done();
} else {
step = 2;
}
} else if (part.isError()) {
return part.asError();
}
}
if (step == 2) {
if (part == null) {
part = http.writeQValue(weight, 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 ContentCodingWriter(http, name, weight, part, step);
}
static Writer<Object, Object> write(Output<?> output, HttpWriter http, String name, float weight) {
return write(output, http, name, weight, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/FieldWriter.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.http;
import swim.codec.Output;
import swim.codec.Writer;
import swim.codec.WriterException;
final class FieldWriter extends Writer<Object, Object> {
final String field;
final int index;
FieldWriter(String field, int index) {
this.field = field;
this.index = index;
}
FieldWriter(String field) {
this(field, 0);
}
@Override
public Writer<Object, Object> pull(Output<?> output) {
return write(output, this.field, this.index);
}
static Writer<Object, Object> write(Output<?> output, String field, int index) {
final int length = field.length();
while (index < length && output.isCont()) {
final int c = field.codePointAt(index);
if (Http.isFieldChar(c)) {
output = output.write(c);
index = field.offsetByCodePoints(index, 1);
} else {
return error(new HttpException("invalid field: " + field));
}
}
if (index >= length) {
return done();
} else if (output.isDone()) {
return error(new WriterException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new FieldWriter(field, index);
}
static Writer<Object, Object> write(Output<?> output, String field) {
return write(output, field, 0);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/Http.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.http;
public final class Http {
private Http() {
// stub
}
private static HttpParser standardParser;
private static HttpWriter standardWriter;
public static HttpParser standardParser() {
if (standardParser == null) {
standardParser = new HttpParser();
}
return standardParser;
}
public static HttpWriter standardWriter() {
if (standardWriter == null) {
standardWriter = new HttpWriter();
}
return standardWriter;
}
public static boolean isSpace(int c) {
return c == 0x20 || c == 0x09;
}
public static boolean isAlpha(int c) {
return c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z';
}
public static boolean isVisibleChar(int c) {
return c >= 0x21 && c <= 0x7e;
}
public static boolean isFieldChar(int c) {
return c >= 0x21 && c <= 0xff;
}
public static boolean isPhraseChar(int c) {
return isSpace(c) || isVisibleChar(c);
}
public static boolean isTokenChar(int c) {
return c == '!' || c == '#'
|| c == '$' || c == '%'
|| c == '&' || c == '\''
|| c == '*' || c == '+'
|| c == '-' || c == '.'
|| c >= '0' && c <= '9'
|| c >= 'A' && c <= 'Z'
|| c == '^' || c == '_'
|| c == '`'
|| c >= 'a' && c <= 'z'
|| c == '|' || c == '~';
}
public static boolean isCommentChar(int c) {
return c == 0x09 || c == 0x20
|| c >= 0x21 && c <= 0x27
|| c >= 0x2a && c <= 0x5b
|| c >= 0x5d && c <= 0x7e
|| c >= 0x80 && c <= 0xff;
}
public static boolean isQuotedChar(int c) {
return c == 0x09 || c == 0x20 || c == 0x21
|| c >= 0x23 && c <= 0x5b
|| c >= 0x5d && c <= 0x7e
|| c >= 0x80 && c <= 0xff;
}
public static boolean isEscapeChar(int c) {
return c == 0x09 || c == 0x20
|| c >= 0x21 && c <= 0x7e
|| c >= 0x80 && c <= 0xff;
}
public static boolean isToken(String token) {
final int n = token.length();
if (n == 0) {
return false;
}
for (int i = 0; i < n; i += 1) {
if (!isTokenChar(token.charAt(i))) {
return false;
}
}
return true;
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpBody.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.http;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import swim.codec.Binary;
import swim.codec.Debug;
import swim.codec.Decoder;
import swim.codec.Encoder;
import swim.codec.Format;
import swim.codec.InputBuffer;
import swim.codec.Output;
import swim.codec.OutputBuffer;
import swim.codec.Utf8;
import swim.collections.FingerTrieSeq;
import swim.http.header.ContentLength;
import swim.http.header.ContentType;
import swim.util.Murmur3;
public final class HttpBody<T> extends HttpEntity<T> implements Debug {
final T value;
final Encoder<?, ?> content;
final long length;
final MediaType mediaType;
HttpBody(T value, Encoder<?, ?> content, long length, MediaType mediaType) {
this.value = value;
this.content = content;
this.length = length;
this.mediaType = mediaType;
}
@Override
public boolean isDefined() {
return this.value != null;
}
@Override
public T get() {
return this.value;
}
public Encoder<?, ?> content() {
return this.content;
}
@Override
public long length() {
return this.length;
}
@Override
public MediaType mediaType() {
return this.mediaType;
}
@Override
public FingerTrieSeq<TransferCoding> transferCodings() {
return FingerTrieSeq.<TransferCoding>empty();
}
@Override
public FingerTrieSeq<HttpHeader> headers() {
FingerTrieSeq<HttpHeader> headers = FingerTrieSeq.empty();
if (this.mediaType != null) {
headers = headers.appended(ContentType.from(this.mediaType));
}
headers = headers.appended(ContentLength.from(this.length));
return headers;
}
@Override
public <T2> Encoder<?, HttpMessage<T2>> httpEncoder(HttpMessage<T2> message, HttpWriter http) {
return http.bodyEncoder(message, this.content, this.length);
}
@Override
public <T2> Encoder<?, HttpMessage<T2>> encodeHttp(HttpMessage<T2> message,
OutputBuffer<?> output, HttpWriter http) {
return http.encodeBody(message, this.content, this.length, output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof HttpBody<?>) {
final HttpBody<?> that = (HttpBody<?>) other;
return (this.value == null ? that.value == null : this.value.equals(that.value))
&& this.content.equals(that.content) && this.length == that.length
&& (this.mediaType == null ? that.mediaType == null : this.mediaType.equals(that.mediaType));
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(HttpBody.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(
hashSeed, Murmur3.hash(this.value)), this.content.hashCode()),
Murmur3.hash(this.length)), Murmur3.hash(this.mediaType)));
}
@Override
public void debug(Output<?> output) {
output = output.write("HttpBody").write('.').write("from").write('(');
if (this.value != null) {
output.debug(this.value).write(", ");
}
output.debug(this.content).write(", ").debug(this.length);
if (this.mediaType != null) {
output = output.write(", ").debug(this.mediaType);
}
output = output.write(')');
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
private static HttpBody<Object> empty;
@SuppressWarnings("unchecked")
public static <T> HttpBody<T> empty() {
if (empty == null) {
empty = new HttpBody<Object>(null, Encoder.done(), 0L, null);
}
return (HttpBody<T>) empty;
}
public static <T> HttpBody<T> from(T value, Encoder<?, ?> content, long length, MediaType mediaType) {
return new HttpBody<T>(value, content, length, mediaType);
}
public static <T> HttpBody<T> from(T value, Encoder<?, ?> content, long length) {
return new HttpBody<T>(value, content, length, MediaType.applicationOctetStream());
}
public static <T> HttpBody<T> from(Encoder<?, ?> content, long length, MediaType mediaType) {
return new HttpBody<T>(null, content, length, mediaType);
}
public static <T> HttpBody<T> from(Encoder<?, ?> content, long length) {
return new HttpBody<T>(null, content, length, MediaType.applicationOctetStream());
}
public static <T> HttpBody<T> from(ByteBuffer data, MediaType mediaType) {
return new HttpBody<T>(null, Binary.byteBufferWriter(data), data.remaining(), mediaType);
}
public static <T> HttpBody<T> from(ByteBuffer data) {
return from(data, MediaType.applicationOctetStream());
}
public static HttpBody<String> from(String content, MediaType mediaType) {
Output<ByteBuffer> output = Utf8.encodedOutput(Binary.byteBufferOutput(content.length()));
output = output.write(content);
final ByteBuffer data = output.bind();
return new HttpBody<String>(content, Binary.byteBufferWriter(data), data.remaining(), mediaType);
}
public static HttpBody<String> from(String content) {
return from(content, MediaType.textPlain());
}
public static <T> HttpBody<T> fromFile(String path, MediaType mediaType) throws IOException {
final FileChannel channel = FileChannel.open(Paths.get(path), StandardOpenOption.READ);
return new HttpBody<T>(null, Binary.channelEncoder(channel), channel.size(), mediaType);
}
public static <T> HttpBody<T> fromFile(String path) throws IOException {
return fromFile(path, MediaType.forPath(path));
}
public static <T> HttpBody<T> fromResource(ClassLoader classLoader, String resource, MediaType mediaType) throws IOException {
HttpBody<T> body = null;
InputStream input = null;
try {
input = classLoader.getResourceAsStream(resource);
if (input != null) {
final ByteBuffer data = Binary.read(Binary.outputParser(Binary.byteBufferOutput()), input);
body = new HttpBody<T>(null, Binary.byteBufferWriter(data), data.remaining(), mediaType);
}
} finally {
try {
if (input != null) {
input.close();
}
} catch (IOException swallow) {
}
}
return body;
}
public static <T> HttpBody<T> fromResource(ClassLoader classLoader, String resource) throws IOException {
return fromResource(classLoader, resource, MediaType.forPath(resource));
}
public static <T> Decoder<HttpMessage<T>> httpDecoder(HttpMessage<?> message, Decoder<T> content, long length) {
return Http.standardParser().bodyDecoder(message, content, length);
}
public static <T> Decoder<HttpMessage<T>> decodeHttp(HttpMessage<?> message, Decoder<T> content,
long length, InputBuffer input) {
return Http.standardParser().decodeBody(message, content, length, input);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpBodyDecoder.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.http;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
import swim.http.header.ContentType;
final class HttpBodyDecoder<T> extends Decoder<HttpMessage<T>> {
final HttpMessage<?> message;
final Decoder<T> content;
final long length;
final long offset;
HttpBodyDecoder(HttpMessage<?> message, Decoder<T> content, long length, long offset) {
this.message = message;
this.content = content;
this.length = length;
this.offset = offset;
}
HttpBodyDecoder(HttpMessage<?> message, Decoder<T> content, long length) {
this(message, content, length, 0L);
}
@Override
public Decoder<HttpMessage<T>> feed(InputBuffer input) {
return decode(input, this.message, this.content, this.length, this.offset);
}
static <T> Decoder<HttpMessage<T>> decode(InputBuffer input, HttpMessage<?> message,
Decoder<T> content, long length, long offset) {
final int inputStart = input.index();
final int inputLimit = input.limit();
int inputRemaining = inputLimit - inputStart;
long outputRemaining = length - offset;
final boolean inputPart = input.isPart();
if (outputRemaining <= inputRemaining) {
input = input.limit(inputStart + (int) outputRemaining).isPart(false);
content = content.feed(input);
input = input.limit(inputLimit);
} else {
input = input.isPart(true);
content = content.feed(input);
}
input = input.isPart(inputPart);
final int inputEnd = input.index();
offset += inputEnd - inputStart;
inputRemaining = inputLimit - inputEnd;
outputRemaining = length - offset;
if (content.isDone() && inputRemaining > 0 && outputRemaining > 0L) {
// Consume excess input.
final int inputExcess = (int) Math.min((long) inputRemaining, outputRemaining);
input = input.index(inputEnd + inputExcess);
offset += inputExcess;
}
if (content.isDone()) {
if (offset < length) {
return error(new DecoderException("buffer underflow"));
} else if (offset > length) {
return error(new DecoderException("buffer overflow"));
} else {
final MediaType mediaType;
final ContentType contentType = message.getHeader(ContentType.class);
if (contentType != null) {
mediaType = contentType.mediaType();
} else {
mediaType = null;
}
final HttpValue<T> entity = HttpValue.from(content.bind(), mediaType);
return done(message.entity(entity));
}
} else if (content.isError()) {
return content.asError();
}
return new HttpBodyDecoder<T>(message, content, length, offset);
}
static <T> Decoder<HttpMessage<T>> decode(InputBuffer input, HttpMessage<?> message,
Decoder<T> content, long length) {
return decode(input, message, content, length, 0L);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpBodyEncoder.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.http;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
final class HttpBodyEncoder<T> extends Encoder<Object, HttpMessage<T>> {
final HttpMessage<T> message;
final Encoder<?, ?> content;
final long length;
final long offset;
HttpBodyEncoder(HttpMessage<T> message, Encoder<?, ?> content, long length, long offset) {
this.message = message;
this.content = content;
this.length = length;
this.offset = offset;
}
HttpBodyEncoder(HttpMessage<T> message, Encoder<?, ?> content, long length) {
this(message, content, length, 0L);
}
@Override
public Encoder<Object, HttpMessage<T>> pull(OutputBuffer<?> output) {
return encode(output, this.message, this.content, this.length, this.offset);
}
static <T> Encoder<Object, HttpMessage<T>> encode(OutputBuffer<?> output, HttpMessage<T> message,
Encoder<?, ?> content, long length, long offset) {
final int outputStart = output.index();
final int outputLimit = output.limit();
final int outputRemaining = outputLimit - outputStart;
final long inputRemaining = length - offset;
final boolean outputPart = output.isPart();
if (inputRemaining <= outputRemaining) {
output = output.limit(outputStart + (int) inputRemaining).isPart(false);
content = content.pull(output);
output = output.limit(outputLimit);
} else {
output = output.isPart(true);
content = content.pull(output);
}
output = output.isPart(outputPart);
offset += output.index() - outputStart;
if (content.isDone()) {
if (offset < length) {
return error(new EncoderException("buffer underflow"));
} else if (offset > length) {
return error(new EncoderException("buffer overflow"));
} else {
return done(message);
}
} else if (content.isError()) {
return content.asError();
}
if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new HttpBodyEncoder<T>(message, content, length, offset);
}
static <T> Encoder<Object, HttpMessage<T>> encode(OutputBuffer<?> output, HttpMessage<T> message,
Encoder<?, ?> content, long length) {
return encode(output, message, content, length, 0L);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpCharset.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.http;
import swim.codec.Debug;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.Writer;
import swim.util.Murmur3;
public final class HttpCharset extends HttpPart implements Debug {
final String name;
final float weight;
HttpCharset(String name, float weight) {
this.name = name;
this.weight = weight;
}
public boolean isStar() {
return "*".equals(this.name);
}
public String name() {
return this.name;
}
public float weight() {
return this.weight;
}
public HttpCharset weight(float weight) {
if (this.weight == weight) {
return this;
} else {
return from(this.name, weight);
}
}
@Override
public Writer<?, ?> httpWriter(HttpWriter http) {
return http.charsetWriter(this.name, this.weight);
}
@Override
public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) {
return http.writeCharset(this.name, this.weight, output);
}
public boolean matches(HttpCharset that) {
if (this == that) {
return true;
} else {
return this.name.equalsIgnoreCase(that.name);
}
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof HttpCharset) {
final HttpCharset that = (HttpCharset) other;
return this.name.equals(that.name) && this.weight == that.weight;
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(HttpCharset.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed,
this.name.hashCode()), Murmur3.hash(this.weight)));
}
@Override
public void debug(Output<?> output) {
output = output.write("HttpCharset").write('.').write("from").write('(').debug(this.name);
if (this.weight != 1f) {
output = output.write(", ").debug(this.weight);
}
output = output.write(')');
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
private static HttpCharset star;
public static HttpCharset star() {
if (star == null) {
star = new HttpCharset("*", 1f);
}
return star;
}
public static HttpCharset from(String name, float weight) {
if (weight == 1f) {
return from(name);
} else {
return new HttpCharset(name, weight);
}
}
public static HttpCharset from(String name) {
if ("*".equals(name)) {
return star();
} else {
return new HttpCharset(name, 1f);
}
}
public static HttpCharset parse(String string) {
return Http.standardParser().parseCharsetString(string);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpCharsetParser.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.http;
import swim.codec.Diagnostic;
import swim.codec.Input;
import swim.codec.Parser;
final class HttpCharsetParser extends Parser<HttpCharset> {
final HttpParser http;
final StringBuilder name;
final Parser<Float> weight;
final int step;
HttpCharsetParser(HttpParser http, StringBuilder name, Parser<Float> weight, int step) {
this.http = http;
this.name = name;
this.weight = weight;
this.step = step;
}
HttpCharsetParser(HttpParser http) {
this(http, null, null, 1);
}
@Override
public Parser<HttpCharset> feed(Input input) {
return parse(input, this.http, this.name, this.weight, this.step);
}
static Parser<HttpCharset> parse(Input input, HttpParser http, StringBuilder name,
Parser<Float> weight, int step) {
int c = 0;
if (step == 1) {
if (input.isCont()) {
c = input.head();
if (Http.isTokenChar(c)) {
input = input.step();
if (name == null) {
name = new StringBuilder();
}
name.appendCodePoint(c);
step = 2;
} else {
return error(Diagnostic.expected("charset", input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected("charset", input));
}
}
if (step == 2) {
while (input.isCont()) {
c = input.head();
if (Http.isTokenChar(c)) {
input = input.step();
name.appendCodePoint(c);
} else {
break;
}
}
if (!input.isEmpty()) {
step = 3;
}
}
if (step == 3) {
if (weight == null) {
weight = http.parseQValue(input);
} else {
weight = weight.feed(input);
}
if (weight.isDone()) {
final Float qvalue = weight.bind();
final float q = qvalue != null ? (float) qvalue : 1f;
return done(http.charset(name.toString(), q));
} else if (weight.isError()) {
return weight.asError();
}
}
if (input.isError()) {
return error(input.trap());
}
return new HttpCharsetParser(http, name, weight, step);
}
static Parser<HttpCharset> parse(Input input, HttpParser http) {
return parse(input, http, null, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpCharsetWriter.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.http;
import swim.codec.Output;
import swim.codec.Writer;
import swim.codec.WriterException;
final class HttpCharsetWriter extends Writer<Object, Object> {
final HttpWriter http;
final String name;
final float weight;
final Writer<?, ?> part;
final int step;
HttpCharsetWriter(HttpWriter http, String name, float weight, Writer<?, ?> part, int step) {
this.http = http;
this.name = name;
this.weight = weight;
this.part = part;
this.step = step;
}
HttpCharsetWriter(HttpWriter http, String name, float weight) {
this(http, name, weight, null, 1);
}
@Override
public Writer<Object, Object> pull(Output<?> output) {
return write(output, this.http, this.name, this.weight, this.part, this.step);
}
static Writer<Object, Object> write(Output<?> output, HttpWriter http, String name, float weight,
Writer<?, ?> part, int step) {
if (step == 1) {
if (part == null) {
part = http.writeToken(name, output);
} else {
part = part.pull(output);
}
if (part.isDone()) {
part = null;
if (weight == 1f) {
return done();
} else {
step = 2;
}
} else if (part.isError()) {
return part.asError();
}
}
if (step == 2) {
if (part == null) {
part = http.writeQValue(weight, 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 HttpCharsetWriter(http, name, weight, part, step);
}
static Writer<Object, Object> write(Output<?> output, HttpWriter http, String name, float weight) {
return write(output, http, name, weight, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpChunk.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.http;
import java.nio.ByteBuffer;
import swim.codec.Binary;
import swim.codec.Debug;
import swim.codec.Encoder;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.OutputBuffer;
import swim.codec.Utf8;
import swim.util.Murmur3;
public final class HttpChunk implements Debug {
final HttpChunkHeader header;
final Encoder<?, ?> content;
public HttpChunk(HttpChunkHeader header, Encoder<?, ?> content) {
this.header = header;
this.content = content;
}
public boolean isEmpty() {
return this.header.isEmpty();
}
public HttpChunkHeader header() {
return this.header;
}
public Encoder<?, ?> content() {
return this.content;
}
public Encoder<?, ?> httpEncoder(HttpWriter http) {
if (this.header.isEmpty()) {
return Utf8.encodedWriter(this.header.httpWriter(http));
} else {
return new HttpChunkEncoder(http, this.header, this.content);
}
}
public Encoder<?, ?> httpEncoder() {
return httpEncoder(Http.standardWriter());
}
public Encoder<?, ?> encodeHttp(OutputBuffer<?> output, HttpWriter http) {
if (this.header.isEmpty()) {
return Utf8.writeEncoded(this.header.httpWriter(http), output);
} else {
return HttpChunkEncoder.encode(output, http, this.header, this.content);
}
}
public Encoder<?, ?> encodeHttp(OutputBuffer<?> output) {
return encodeHttp(output, Http.standardWriter());
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof HttpChunk) {
final HttpChunk that = (HttpChunk) other;
return this.header.equals(that.header) && this.content.equals(that.content);
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(HttpChunk.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed,
this.header.hashCode()), this.content.hashCode()));
}
@Override
public void debug(Output<?> output) {
output = output.write("HttpChunk").write('.');
if (header != HttpChunkHeader.sentinel()) {
output = output.write("from").write('(').debug(this.header).write(", ").debug(this.content).write(')');
} else {
output = output.write("last").write('(').write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
private static HttpChunk last;
public static HttpChunk last() {
if (last == null) {
last = new HttpChunk(HttpChunkHeader.sentinel(), Encoder.done());
}
return last;
}
public static HttpChunk from(int length, Encoder<?, ?> content) {
final HttpChunkHeader header = HttpChunkHeader.from(length);
return new HttpChunk(header, content);
}
public static HttpChunk from(ByteBuffer data) {
final HttpChunkHeader header = HttpChunkHeader.from(data.remaining());
return new HttpChunk(header, Binary.byteBufferWriter(data));
}
public static HttpChunk from(String text) {
Output<ByteBuffer> output = Utf8.encodedOutput(Binary.byteBufferOutput(text.length()));
output = output.write(text);
final ByteBuffer data = output.bind();
final HttpChunkHeader header = HttpChunkHeader.from(data.remaining());
return new HttpChunk(header, Binary.byteBufferWriter(data));
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpChunkEncoder.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.http;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
import swim.codec.Utf8;
import swim.codec.Writer;
final class HttpChunkEncoder extends Encoder<Object, Object> {
final HttpWriter http;
final HttpChunkHeader header;
final Encoder<?, ?> content;
final Writer<?, ?> part;
final int step;
HttpChunkEncoder(HttpWriter http, HttpChunkHeader header, Encoder<?, ?> content,
Writer<?, ?> part, int step) {
this.http = http;
this.header = header;
this.content = content;
this.part = part;
this.step = step;
}
HttpChunkEncoder(HttpWriter http, HttpChunkHeader header, Encoder<?, ?> content) {
this(http, header, content, null, 1);
}
@Override
public Encoder<Object, Object> pull(OutputBuffer<?> output) {
return encode(output, this.http, this.header, this.content, this.part, this.step);
}
static Encoder<Object, Object> encode(OutputBuffer<?> output, HttpWriter http, HttpChunkHeader header,
Encoder<?, ?> content, Writer<?, ?> part, int step) {
if (step == 1) {
if (part == null) {
part = Utf8.writeEncoded(header.httpWriter(http), output);
} else {
part = part.pull(output);
}
if (part.isDone()) {
part = null;
step = 2;
} else if (part.isError()) {
return error(part.trap());
}
}
if (step == 2) {
content = content.pull(output);
if (content.isDone()) {
step = 3;
} else if (content.isError()) {
return content.asError();
}
}
if (step == 3 && output.isCont()) {
output = output.write('\r');
step = 4;
}
if (step == 4 && output.isCont()) {
output = output.write('\n');
return done();
}
if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new HttpChunkEncoder(http, header, content, part, step);
}
static Encoder<Object, Object> encode(OutputBuffer<?> output, HttpWriter http,
HttpChunkHeader header, Encoder<?, ?> content) {
return encode(output, http, header, content, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpChunkHeader.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.http;
import swim.codec.Debug;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.Writer;
import swim.collections.FingerTrieSeq;
import swim.util.Murmur3;
public final class HttpChunkHeader extends HttpPart implements Debug {
final long size;
final FingerTrieSeq<ChunkExtension> extensions;
HttpChunkHeader(long size, FingerTrieSeq<ChunkExtension> extensions) {
this.size = size;
this.extensions = extensions;
}
public boolean isEmpty() {
return this.size == 0L;
}
public long size() {
return this.size;
}
public FingerTrieSeq<ChunkExtension> extensions() {
return this.extensions;
}
@Override
public Writer<?, ?> httpWriter(HttpWriter http) {
return http.chunkHeaderWriter(this.size, this.extensions.iterator());
}
@Override
public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) {
return http.writeChunkHeader(this.size, this.extensions.iterator(), output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof HttpChunkHeader) {
final HttpChunkHeader that = (HttpChunkHeader) other;
return this.size == that.size && this.extensions.equals(that.extensions);
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(HttpChunkHeader.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed,
Murmur3.hash(this.size)), this.extensions.hashCode()));
}
@Override
public void debug(Output<?> output) {
output = output.write("HttpChunkHeader").write('.');
if (this.size != 0L || !this.extensions.isEmpty()) {
output = output.write("from").write('(').debug(this.size);
for (ChunkExtension extension : this.extensions) {
output = output.write(", ").debug(extension);
}
output = output.write(')');
} else {
output = output.write("sentinel").write('(').write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
private static HttpChunkHeader sentinel;
public static HttpChunkHeader sentinel() {
if (sentinel == null) {
sentinel = new HttpChunkHeader(0L, FingerTrieSeq.<ChunkExtension>empty());
}
return sentinel;
}
public static HttpChunkHeader from(long size, FingerTrieSeq<ChunkExtension> extensions) {
if (size == 0L && extensions.isEmpty()) {
return sentinel();
} else {
return new HttpChunkHeader(size, extensions);
}
}
public static HttpChunkHeader from(long size, ChunkExtension... extensions) {
if (size == 0L && extensions.length == 0) {
return sentinel();
} else {
return new HttpChunkHeader(size, FingerTrieSeq.of(extensions));
}
}
public static HttpChunkHeader from(long size) {
if (size == 0L) {
return sentinel();
} else {
return new HttpChunkHeader(size, FingerTrieSeq.<ChunkExtension>empty());
}
}
public static HttpChunkHeader parse(String string) {
return Http.standardParser().parseChunkHeaderString(string);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpChunkHeaderParser.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.http;
import swim.codec.Base16;
import swim.codec.Diagnostic;
import swim.codec.Input;
import swim.codec.Parser;
import swim.collections.FingerTrieSeq;
import swim.util.Builder;
final class HttpChunkHeaderParser extends Parser<HttpChunkHeader> {
final HttpParser http;
final long size;
final Parser<ChunkExtension> extension;
final Builder<ChunkExtension, FingerTrieSeq<ChunkExtension>> extensions;
final int step;
HttpChunkHeaderParser(HttpParser http, long size, Parser<ChunkExtension> extension,
Builder<ChunkExtension, FingerTrieSeq<ChunkExtension>> extensions, int step) {
this.http = http;
this.size = size;
this.extension = extension;
this.extensions = extensions;
this.step = step;
}
HttpChunkHeaderParser(HttpParser http) {
this(http, 0L, null, null, 1);
}
@Override
public Parser<HttpChunkHeader> feed(Input input) {
return parse(input, this.http, this.size, this.extension, this.extensions, this.step);
}
static Parser<HttpChunkHeader> parse(Input input, HttpParser http, long size, Parser<ChunkExtension> extension,
Builder<ChunkExtension, FingerTrieSeq<ChunkExtension>> extensions, int step) {
int c = 0;
if (step == 1) {
if (input.isCont()) {
c = input.head();
if (Base16.isDigit(c)) {
input = input.step();
size = Base16.decodeDigit(c);
step = 2;
} else {
return error(Diagnostic.expected("chunk size", input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected("chunk size", input));
}
}
if (step == 2) {
while (input.isCont()) {
c = input.head();
if (Base16.isDigit(c)) {
input = input.step();
size = (size << 4) | Base16.decodeDigit(c);
if (size < 0L) {
return error(Diagnostic.message("chunk size overflow", input));
}
} else {
break;
}
}
if (!input.isEmpty()) {
step = 3;
}
}
do {
if (step == 3) {
if (input.isCont()) {
c = input.head();
if (c == ';') {
step = 4;
} else {
step = 5;
break;
}
} else if (input.isDone()) {
return error(Diagnostic.unexpected(input));
}
}
if (step == 4) {
if (extension == null) {
extension = http.parseChunkExtension(input);
} else {
extension = extension.feed(input);
}
if (extension.isDone()) {
if (extensions == null) {
extensions = FingerTrieSeq.builder();
}
extensions.add(extension.bind());
extension = null;
step = 3;
continue;
} else if (extension.isError()) {
return extension.asError();
}
}
break;
} while (true);
if (step == 5) {
if (input.isCont()) {
c = input.head();
if (c == '\r') {
input = input.step();
step = 6;
} else {
return error(Diagnostic.expected("carriage return", input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected("carriage return", input));
}
}
if (step == 6) {
if (input.isCont()) {
c = input.head();
if (c == '\n') {
input = input.step();
if (extensions == null) {
return done(http.chunkHeader(size, FingerTrieSeq.<ChunkExtension>empty()));
} else {
return done(http.chunkHeader(size, extensions.bind()));
}
} else {
return error(Diagnostic.expected("line feed", input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected("line feed", input));
}
}
if (input.isError()) {
return error(input.trap());
}
return new HttpChunkHeaderParser(http, size, extension, extensions, step);
}
static Parser<HttpChunkHeader> parse(Input input, HttpParser http) {
return parse(input, http, 0L, null, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpChunkHeaderWriter.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.http;
import java.util.Iterator;
import swim.codec.Base16;
import swim.codec.Output;
import swim.codec.Writer;
import swim.codec.WriterException;
final class HttpChunkHeaderWriter extends Writer<Object, Object> {
final HttpWriter http;
final long size;
final Iterator<ChunkExtension> extensions;
final Writer<?, ?> part;
final int step;
HttpChunkHeaderWriter(HttpWriter http, long size, Iterator<ChunkExtension> extensions,
Writer<?, ?> part, int step) {
this.http = http;
this.size = size;
this.extensions = extensions;
this.part = part;
this.step = step;
}
HttpChunkHeaderWriter(HttpWriter http, long size, Iterator<ChunkExtension> extensions) {
this(http, size, extensions, null, 1);
}
@Override
public Writer<Object, Object> pull(Output<?> output) {
return write(output, this.http, this.size, this.extensions, this.part, this.step);
}
static Writer<Object, Object> write(Output<?> output, HttpWriter http, long size,
Iterator<ChunkExtension> extensions,
Writer<?, ?> part, int step) {
if (step == 1) {
if (part == null) {
part = Base16.uppercase().writeLong(size, output);
} else {
part = part.pull(output);
}
if (part.isDone()) {
part = null;
step = 2;
} else if (part.isError()) {
return part.asError();
}
}
do {
if (step == 2) {
if (!extensions.hasNext()) {
step = 4;
} else if (output.isCont()) {
output = output.write(';');
step = 3;
}
}
if (step == 3) {
if (part == null) {
part = extensions.next().writeHttp(output, http);
} else {
part = part.pull(output);
}
if (part.isDone()) {
part = null;
step = 2;
continue;
} else if (part.isError()) {
return part.asError();
}
}
break;
} while (true);
if (step == 4 && output.isCont()) {
output = output.write('\r');
step = 5;
}
if (step == 5 && output.isCont()) {
output = output.write('\n');
return done();
}
if (output.isDone()) {
return error(new WriterException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new HttpChunkHeaderWriter(http, size, extensions, part, step);
}
static Writer<Object, Object> write(Output<?> output, HttpWriter http, long size,
Iterator<ChunkExtension> extensions) {
return write(output, http, size, extensions, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpChunkTrailer.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.http;
import java.util.Iterator;
import swim.codec.Debug;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.Writer;
import swim.collections.FingerTrieSeq;
import swim.util.Murmur3;
public final class HttpChunkTrailer extends HttpPart implements Debug {
final FingerTrieSeq<HttpHeader> headers;
HttpChunkTrailer(FingerTrieSeq<HttpHeader> headers) {
this.headers = headers;
}
public FingerTrieSeq<HttpHeader> headers() {
return this.headers;
}
@Override
public Writer<?, ?> httpWriter(HttpWriter http) {
return http.chunkTrailerWriter(this.headers.iterator());
}
@Override
public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) {
return http.writeChunkTrailer(this.headers.iterator(), output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof HttpChunkTrailer) {
final HttpChunkTrailer that = (HttpChunkTrailer) other;
return this.headers.equals(that.headers);
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(HttpChunkTrailer.class);
}
return Murmur3.mash(Murmur3.mix(hashSeed, this.headers.hashCode()));
}
@Override
public void debug(Output<?> output) {
output = output.write("HttpChunkTrailer").write('.');
final Iterator<HttpHeader> headers = this.headers.iterator();
if (headers.hasNext()) {
output = output.write("apply").write('(').debug(headers.next());
while (headers.hasNext()) {
output = output.write(", ").debug(headers.next());
}
output = output.write(')');
} else {
output = output.write("empty").write('(').write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
private static HttpChunkTrailer empty;
public static HttpChunkTrailer empty() {
if (empty == null) {
empty = new HttpChunkTrailer(FingerTrieSeq.<HttpHeader>empty());
}
return empty;
}
public static HttpChunkTrailer from(FingerTrieSeq<HttpHeader> headers) {
if (headers.isEmpty()) {
return empty();
} else {
return new HttpChunkTrailer(headers);
}
}
public static HttpChunkTrailer from(HttpHeader... headers) {
if (headers.length == 0) {
return empty();
} else {
return new HttpChunkTrailer(FingerTrieSeq.of(headers));
}
}
public static HttpChunkTrailer parse(String chunkTrailer) {
return Http.standardParser().parseChunkTrailerString(chunkTrailer);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpChunkTrailerParser.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.http;
import swim.codec.Diagnostic;
import swim.codec.Input;
import swim.codec.Parser;
import swim.collections.FingerTrieSeq;
import swim.util.Builder;
final class HttpChunkTrailerParser extends Parser<HttpChunkTrailer> {
final HttpParser http;
final Parser<? extends HttpHeader> header;
final Builder<HttpHeader, FingerTrieSeq<HttpHeader>> headers;
final int step;
HttpChunkTrailerParser(HttpParser http, Parser<? extends HttpHeader> header,
Builder<HttpHeader, FingerTrieSeq<HttpHeader>> headers, int step) {
this.http = http;
this.header = header;
this.headers = headers;
this.step = step;
}
HttpChunkTrailerParser(HttpParser http) {
this(http, null, null, 1);
}
@Override
public Parser<HttpChunkTrailer> feed(Input input) {
return parse(input, this.http, this.header, this.headers, this.step);
}
static Parser<HttpChunkTrailer> parse(Input input, HttpParser http, Parser<? extends HttpHeader> header,
Builder<HttpHeader, FingerTrieSeq<HttpHeader>> headers, int step) {
int c = 0;
do {
if (step == 1) {
if (input.isCont()) {
c = input.head();
if (Http.isTokenChar(c)) {
step = 2;
} else if (Http.isSpace(c)) {
return error(Diagnostic.message("unsupported header line extension", input));
} else if (c == '\r') {
input = input.step();
step = 5;
} else {
return error(Diagnostic.expected("chunk trailer", input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected("chunk trailer", input));
}
}
if (step == 2) {
if (header == null) {
header = http.parseHeader(input);
} else {
header = header.feed(input);
}
if (header.isDone()) {
step = 3;
} else if (header.isError()) {
return header.asError();
}
}
if (step == 3) {
if (input.isCont()) {
c = input.head();
if (c == '\r') {
input = input.step();
step = 4;
} else {
return error(Diagnostic.expected("carriage return", input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected("carriage return", input));
}
}
if (step == 4) {
if (input.isCont()) {
c = input.head();
if (c == '\n') {
input = input.step();
if (headers == null) {
headers = FingerTrieSeq.builder();
}
headers.add(header.bind());
header = null;
step = 1;
continue;
} else {
return error(Diagnostic.expected("line feed", input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected("line feed", input));
}
}
break;
} while (true);
if (step == 5) {
if (input.isCont()) {
c = input.head();
if (c == '\n') {
input = input.step();
if (headers == null) {
return done(http.chunkTrailer(FingerTrieSeq.<HttpHeader>empty()));
} else {
return done(http.chunkTrailer(headers.bind()));
}
} else {
return error(Diagnostic.expected("line feed", input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected("line feed", input));
}
}
if (input.isError()) {
return error(input.trap());
}
return new HttpChunkTrailerParser(http, header, headers, step);
}
static Parser<HttpChunkTrailer> parse(Input input, HttpParser http) {
return parse(input, http, null, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpChunkTrailerWriter.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.http;
import java.util.Iterator;
import swim.codec.Output;
import swim.codec.Writer;
import swim.codec.WriterException;
final class HttpChunkTrailerWriter extends Writer<Object, Object> {
final HttpWriter http;
final Iterator<HttpHeader> headers;
final Writer<?, ?> part;
final int step;
HttpChunkTrailerWriter(HttpWriter http, Iterator<HttpHeader> headers,
Writer<?, ?> part, int step) {
this.http = http;
this.headers = headers;
this.part = part;
this.step = step;
}
HttpChunkTrailerWriter(HttpWriter http, Iterator<HttpHeader> headers) {
this(http, headers, null, 1);
}
@Override
public Writer<Object, Object> pull(Output<?> output) {
return write(output, this.http, this.headers, this.part, this.step);
}
static Writer<Object, Object> write(Output<?> output, HttpWriter http,
Iterator<HttpHeader> headers,
Writer<?, ?> part, int step) {
do {
if (step == 1) {
if (part == null) {
if (!headers.hasNext()) {
step = 4;
break;
} else {
part = headers.next().writeHttp(output, http);
}
} 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('\r');
step = 3;
}
if (step == 3 && output.isCont()) {
output = output.write('\n');
step = 1;
continue;
}
break;
} while (true);
if (step == 4 && output.isCont()) {
output = output.write('\r');
step = 5;
}
if (step == 5 && output.isCont()) {
output = output.write('\n');
return done();
}
if (output.isDone()) {
return error(new WriterException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new HttpChunkTrailerWriter(http, headers, part, step);
}
static Writer<Object, Object> write(Output<?> output, HttpWriter http,
Iterator<HttpHeader> headers) {
return write(output, http, headers, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpChunked.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.http;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import swim.codec.Binary;
import swim.codec.Debug;
import swim.codec.Decoder;
import swim.codec.Encoder;
import swim.codec.Format;
import swim.codec.InputBuffer;
import swim.codec.Output;
import swim.codec.OutputBuffer;
import swim.collections.FingerTrieSeq;
import swim.http.header.ContentType;
import swim.http.header.TransferEncoding;
import swim.util.Murmur3;
public final class HttpChunked<T> extends HttpEntity<T> implements Debug {
final T value;
final Encoder<?, ?> content;
final MediaType mediaType;
HttpChunked(T value, Encoder<?, ?> content, MediaType mediaType) {
this.value = value;
this.content = content;
this.mediaType = mediaType;
}
@Override
public boolean isDefined() {
return this.value != null;
}
@Override
public T get() {
return this.value;
}
public Encoder<?, ?> content() {
return this.content;
}
@Override
public long length() {
return -1L;
}
@Override
public MediaType mediaType() {
return this.mediaType;
}
@Override
public FingerTrieSeq<TransferCoding> transferCodings() {
return TransferEncoding.chunked().codings();
}
@Override
public FingerTrieSeq<HttpHeader> headers() {
FingerTrieSeq<HttpHeader> headers = FingerTrieSeq.empty();
if (this.mediaType != null) {
headers = headers.appended(ContentType.from(mediaType));
}
headers = headers.appended(TransferEncoding.chunked());
return headers;
}
@Override
public <T2> Encoder<?, HttpMessage<T2>> httpEncoder(HttpMessage<T2> message, HttpWriter http) {
return http.chunkedEncoder(message, this.content);
}
@Override
public <T2> Encoder<?, HttpMessage<T2>> encodeHttp(HttpMessage<T2> message,
OutputBuffer<?> output, HttpWriter http) {
return http.encodeChunked(message, this.content, output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof HttpChunked<?>) {
final HttpChunked<?> that = (HttpChunked<?>) other;
return (this.value == null ? that.value == null : this.value.equals(that.value))
&& this.content.equals(that.content)
&& (this.mediaType == null ? that.mediaType == null : this.mediaType.equals(that.mediaType));
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(HttpChunked.class);
}
return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(hashSeed,
Murmur3.hash(this.value)), this.content.hashCode()), Murmur3.hash(this.mediaType)));
}
@Override
public void debug(Output<?> output) {
output = output.write("HttpChunked").write('.').write("from").write('(');
if (this.value != null) {
output.debug(this.value).write(", ");
}
output.debug(this.content);
if (this.mediaType != null) {
output = output.write(", ").debug(this.mediaType);
}
output = output.write(')');
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
public static <T> HttpChunked<T> from(T value, Encoder<?, T> content, MediaType mediaType) {
return new HttpChunked<T>(value, content, mediaType);
}
public static <T> HttpChunked<T> from(T value, Encoder<?, T> content) {
return new HttpChunked<T>(value, content, null);
}
public static <T> HttpChunked<T> from(Encoder<?, T> content, MediaType mediaType) {
return new HttpChunked<T>(null, content, mediaType);
}
public static <T> HttpChunked<T> from(Encoder<?, T> content) {
return new HttpChunked<T>(null, content, null);
}
public static <T> HttpChunked<T> fromFile(String path, MediaType mediaType) throws IOException {
final FileChannel channel = FileChannel.open(Paths.get(path), StandardOpenOption.READ);
return new HttpChunked<T>(null, Binary.channelEncoder(channel), mediaType);
}
public static <T> HttpChunked<T> fromFile(String path) throws IOException {
return fromFile(path, MediaType.forPath(path));
}
public static <T> Decoder<HttpMessage<T>> httpDecoder(HttpMessage<?> message, Decoder<T> content) {
return Http.standardParser().chunkedDecoder(message, content);
}
public static <T> Decoder<HttpMessage<T>> decodeHttp(HttpMessage<?> message, Decoder<T> content,
InputBuffer input) {
return Http.standardParser().decodeChunked(message, content, input);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpChunkedDecoder.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.http;
import swim.codec.Decoder;
import swim.codec.DecoderException;
import swim.codec.InputBuffer;
import swim.codec.Parser;
import swim.codec.Utf8;
import swim.http.header.ContentType;
final class HttpChunkedDecoder<T> extends Decoder<HttpMessage<T>> {
final HttpParser http;
final HttpMessage<?> message;
final Decoder<T> content;
final HttpChunkHeader header;
final Parser<?> part;
final int offset;
final int step;
HttpChunkedDecoder(HttpParser http, HttpMessage<?> message, Decoder<T> content,
HttpChunkHeader header, Parser<?> part, int offset, int step) {
this.http = http;
this.message = message;
this.content = content;
this.header = header;
this.part = part;
this.offset = offset;
this.step = step;
}
HttpChunkedDecoder(HttpParser http, HttpMessage<?> message, Decoder<T> content) {
this(http, message, content, null, null, 0, 1);
}
@Override
public Decoder<HttpMessage<T>> feed(InputBuffer input) {
return decode(input, this.http, this.message, this.content, this.header,
this.part, this.offset, this.step);
}
static <T> Decoder<HttpMessage<T>> decode(InputBuffer input, HttpParser http,
HttpMessage<?> message, Decoder<T> content,
HttpChunkHeader header, Parser<?> part,
int offset, int step) {
do {
if (step == 1) { // chunk header
if (part == null) {
part = Utf8.parseDecoded(http.chunkHeaderParser(), input);
} else {
part = part.feed(input);
}
if (part.isDone()) {
header = (HttpChunkHeader) part.bind();
part = null;
step = 2;
} else if (part.isError()) {
return error(part.trap());
}
}
if (step == 2) { // chunk data
final int inputStart = input.index();
final int inputLimit = input.limit();
final int inputRemaining = inputLimit - inputStart;
final long chunkSize = header.size();
final long chunkRemaining = chunkSize - offset;
final boolean inputPart = input.isPart();
if (chunkRemaining < inputRemaining) {
input = input.limit(inputStart + (int) chunkRemaining).isPart(chunkSize != 0);
content = content.feed(input);
input = input.limit(inputLimit);
} else {
input = input.isPart(chunkSize != 0);
content = content.feed(input);
}
input = input.isPart(inputPart);
offset += input.index() - inputStart;
if (offset >= chunkSize) {
offset = 0;
if (chunkSize > 0) {
step = 3;
} else {
step = 5;
break;
}
} else if (content.isError()) {
return content.asError();
}
}
if (step == 3) {
if (input.isCont()) {
if (input.head() == '\r') {
input = input.step();
step = 4;
} else {
return error(new DecoderException("carriage return"));
}
}
}
if (step == 4) {
if (input.isCont()) {
if (input.head() == '\n') {
input = input.step();
step = 1;
continue;
} else {
return error(new DecoderException("line feed"));
}
}
}
break;
} while (true);
if (step == 5) { // chunk trailer
if (part == null) {
part = Utf8.parseDecoded(http.chunkTrailerParser(), input);
} else {
part = part.feed(input);
}
if (part.isDone()) {
final HttpChunkTrailer trailer = (HttpChunkTrailer) part.bind();
message = message.appendedHeaders(trailer.headers());
final MediaType mediaType;
final ContentType contentType = message.getHeader(ContentType.class);
if (contentType != null) {
mediaType = contentType.mediaType();
} else {
mediaType = null;
}
final HttpValue<T> entity = HttpValue.from(content.bind(), mediaType);
return done(message.entity(entity));
} else if (part.isError()) {
return error(part.trap());
}
}
return new HttpChunkedDecoder<T>(http, message, content, header, part, offset, step);
}
static <T> Decoder<HttpMessage<T>> decode(InputBuffer input, HttpParser http,
HttpMessage<?> message, Decoder<T> content) {
return decode(input, http, message, content, null, null, 0, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpChunkedEncoder.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.http;
import swim.codec.Base16;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
final class HttpChunkedEncoder<T> extends Encoder<Object, HttpMessage<T>> {
final HttpMessage<T> message;
final Encoder<?, ?> content;
final int step;
HttpChunkedEncoder(HttpMessage<T> message, Encoder<?, ?> content, int step) {
this.message = message;
this.content = content;
this.step = step;
}
HttpChunkedEncoder(HttpMessage<T> message, Encoder<?, ?> content) {
this(message, content, 1);
}
@Override
public Encoder<Object, HttpMessage<T>> pull(OutputBuffer<?> output) {
return encode(output, this.message, this.content, this.step);
}
static <T> Encoder<Object, HttpMessage<T>> encode(OutputBuffer<?> output, HttpMessage<T> message,
Encoder<?, ?> content, int step) {
if (step == 1 && output.remaining() > 12) { // chunk
final int outputStart = output.index();
final int outputEnd = output.limit();
final boolean outputPart = output.isPart();
output = output.index(outputStart + 10); // chunk header
output = output.limit(outputEnd - 2); // chunk footer
output = output.isPart(true);
content = content.pull(output);
final int chunkSize = output.index() - outputStart - 10;
output = output.limit(outputEnd).isPart(outputPart);
if (chunkSize > 0) {
output = output.write('\r').write('\n');
} else if (content.isCont()) {
output = output.index(outputStart);
return new HttpChunkedEncoder<T>(message, content, step);
}
final int chunkEnd = output.index();
output = output.index(outputStart + 8).write('\r').write('\n');
int chunkStart = outputStart + 7;
int x = chunkSize;
do {
output = output.index(chunkStart).write(Base16.uppercase().encodeDigit(x & 0xf));
x >>>= 4;
if (x != 0) {
chunkStart -= 1;
} else {
break;
}
} while (true);
final int chunkLength = chunkEnd - chunkStart;
output = output.move(chunkStart, outputStart, chunkLength)
.index(outputStart + chunkLength);
if (content.isDone()) {
if (chunkSize > 0) {
step = 2;
} else {
step = 3;
}
} else if (content.isError()) {
return content.asError();
}
}
if (step == 2 && output.remaining() >= 3) { // last chunk
output = output.write('0').write('\r').write('\n');
step = 3;
}
if (step == 3 && output.remaining() >= 2) { // chunk trailer
output = output.write('\r').write('\n');
return done(message);
}
if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new HttpChunkedEncoder<T>(message, content, step);
}
static <T> Encoder<Object, HttpMessage<T>> encode(OutputBuffer<?> output, HttpMessage<T> message,
Encoder<?, ?> content) {
return encode(output, message, content, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpEmpty.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.http;
import swim.codec.Debug;
import swim.codec.Encoder;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.OutputBuffer;
import swim.collections.FingerTrieSeq;
final class HttpEmpty extends HttpEntity<Object> implements Debug {
@Override
public boolean isDefined() {
return false;
}
@Override
public Object get() {
return null;
}
@Override
public long length() {
return 0L;
}
@Override
public MediaType mediaType() {
return null;
}
@Override
public FingerTrieSeq<TransferCoding> transferCodings() {
return FingerTrieSeq.empty();
}
@Override
public FingerTrieSeq<HttpHeader> headers() {
return FingerTrieSeq.empty();
}
@Override
public <T2> Encoder<?, HttpMessage<T2>> httpEncoder(HttpMessage<T2> message, HttpWriter http) {
return Encoder.done(message);
}
@Override
public <T2> Encoder<?, HttpMessage<T2>> encodeHttp(HttpMessage<T2> message,
OutputBuffer<?> output, HttpWriter http) {
return Encoder.done(message);
}
@Override
public void debug(Output<?> output) {
output = output.write("HttpEntity").write('.').write("empty").write('(').write(')');
}
@Override
public String toString() {
return Format.debug(this);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpEntity.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.http;
import swim.codec.Encoder;
import swim.codec.OutputBuffer;
import swim.collections.FingerTrieSeq;
public abstract class HttpEntity<T> {
public abstract boolean isDefined();
public abstract T get();
public abstract long length();
public abstract MediaType mediaType();
public abstract FingerTrieSeq<TransferCoding> transferCodings();
public abstract FingerTrieSeq<HttpHeader> headers();
public abstract <T2> Encoder<?, HttpMessage<T2>> httpEncoder(HttpMessage<T2> message, HttpWriter http);
public <T2> Encoder<?, HttpMessage<T2>> httpEncoder(HttpMessage<T2> message) {
return httpEncoder(message, Http.standardWriter());
}
public abstract <T2> Encoder<?, HttpMessage<T2>> encodeHttp(HttpMessage<T2> message,
OutputBuffer<?> output, HttpWriter http);
public <T2> Encoder<?, HttpMessage<T2>> encodeHttp(HttpMessage<T2> message, OutputBuffer<?> output) {
return encodeHttp(message, output, Http.standardWriter());
}
private static HttpEntity<Object> empty;
@SuppressWarnings("unchecked")
public static <T> HttpEntity<T> empty() {
if (empty == null) {
empty = new HttpEmpty();
}
return (HttpEntity<T>) empty;
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpException.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.http;
public class HttpException extends RuntimeException {
private static final long serialVersionUID = 1L;
public HttpException(String message, Throwable cause) {
super(message, cause);
}
public HttpException(String message) {
super(message);
}
public HttpException(Throwable cause) {
super(cause);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpHeader.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.http;
import swim.codec.Debug;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.Utf8;
import swim.codec.Writer;
public abstract class HttpHeader extends HttpPart implements Debug {
public boolean isBlank() {
return false;
}
public abstract String lowerCaseName();
public abstract String name();
public String value() {
final Output<String> output = Utf8.decodedString();
writeHttpValue(output, Http.standardWriter());
return output.bind();
}
@Override
public Writer<?, ?> httpWriter(HttpWriter http) {
return http.headerWriter(this);
}
@Override
public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) {
return http.writeHeader(this, output);
}
public abstract Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http);
@Override
public String toString() {
return Format.debug(this);
}
public static HttpHeader parseHttp(String string) {
return Http.standardParser().parseHeaderString(string);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpHeaderParser.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.http;
import swim.codec.Diagnostic;
import swim.codec.Input;
import swim.codec.Parser;
final class HttpHeaderParser extends Parser<HttpHeader> {
final HttpParser http;
final StringBuilder name;
final Parser<? extends HttpHeader> value;
final int step;
HttpHeaderParser(HttpParser http, StringBuilder name, Parser<? extends HttpHeader> value, int step) {
this.http = http;
this.name = name;
this.value = value;
this.step = step;
}
HttpHeaderParser(HttpParser http) {
this(http, null, null, 1);
}
@Override
public Parser<HttpHeader> feed(Input input) {
return parse(input, this.http, this.name, this.value, this.step);
}
@SuppressWarnings("unchecked")
static Parser<HttpHeader> parse(Input input, HttpParser http, StringBuilder name,
Parser<? extends HttpHeader> value, int step) {
int c = 0;
if (step == 1) {
if (input.isCont()) {
c = input.head();
if (Http.isTokenChar(c)) {
input = input.step();
if (name == null) {
name = new StringBuilder();
}
name.appendCodePoint(c);
step = 2;
} else {
return error(Diagnostic.expected("HTTP header name", input));
}
} else if (input.isDone()) {
return error(Diagnostic.expected("HTTP header name", input));
}
}
if (step == 2) {
while (input.isCont()) {
c = input.head();
if (Http.isTokenChar(c)) {
input = input.step();
name.appendCodePoint(c);
} else {
break;
}
}
if (input.isCont()) {
step = 3;
} else if (input.isDone()) {
return error(Diagnostic.unexpected(input));
}
}
if (step == 3) {
if (input.isCont() && input.head() == ':') {
input = input.step();
step = 4;
} else if (!input.isEmpty()) {
return error(Diagnostic.expected(':', input));
}
}
if (step == 4) {
while (input.isCont()) {
c = input.head();
if (Http.isSpace(c)) {
input = input.step();
} else {
break;
}
}
if (!input.isEmpty()) {
step = 5;
}
}
if (step == 5) {
if (value == null) {
value = http.parseHeaderValue(name.toString(), input);
} else {
value = value.feed(input);
}
if (value.isDone()) {
step = 6;
} else if (value.isError()) {
return value.asError();
}
}
if (step == 6) {
while (input.isCont()) {
c = input.head();
if (Http.isSpace(c)) {
input = input.step();
} else {
break;
}
}
if (!input.isEmpty()) {
return (Parser<HttpHeader>) value;
}
}
if (input.isError()) {
return error(input.trap());
}
return new HttpHeaderParser(http, name, value, step);
}
static Parser<HttpHeader> parse(Input input, HttpParser http) {
return parse(input, http, null, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpHeaderWriter.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.http;
import swim.codec.Output;
import swim.codec.Writer;
import swim.codec.WriterException;
final class HttpHeaderWriter extends Writer<Object, Object> {
final HttpWriter http;
final HttpHeader header;
final Writer<?, ?> part;
final int step;
HttpHeaderWriter(HttpWriter http, HttpHeader header, Writer<?, ?> part, int step) {
this.http = http;
this.header = header;
this.part = part;
this.step = step;
}
HttpHeaderWriter(HttpWriter http, HttpHeader header) {
this(http, header, null, 1);
}
@Override
public Writer<Object, Object> pull(Output<?> output) {
return write(output, this.http, this.header, this.part, this.step);
}
static Writer<Object, Object> write(Output<?> output, HttpWriter http,
HttpHeader header, Writer<?, ?> part, int step) {
if (step == 1) {
if (part == null) {
part = http.writeToken(header.name(), 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 (header.isBlank()) {
return done();
} else {
step = 3;
}
}
if (step == 3 && output.isCont()) {
output = output.write(' ');
step = 4;
}
if (step == 4) {
if (part == null) {
part = http.writeHeaderValue(header, 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 HttpHeaderWriter(http, header, part, step);
}
static Writer<Object, Object> write(Output<?> output, HttpWriter http, HttpHeader header) {
return write(output, http, header, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpMessage.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.http;
import swim.codec.Decoder;
import swim.codec.Encoder;
import swim.codec.OutputBuffer;
import swim.codec.Utf8;
import swim.collections.FingerTrieSeq;
import swim.collections.HashTrieSet;
import swim.decipher.Decipher;
import swim.http.header.ContentLength;
import swim.http.header.ContentType;
import swim.http.header.TransferEncoding;
import swim.json.Json;
import swim.recon.Recon;
import swim.util.Builder;
import swim.xml.Xml;
public abstract class HttpMessage<T> extends HttpPart {
public abstract HttpVersion version();
public abstract FingerTrieSeq<HttpHeader> headers();
public HttpHeader getHeader(String name) {
final FingerTrieSeq<HttpHeader> headers = headers();
for (int i = 0, n = headers.size(); i < n; i += 1) {
final HttpHeader header = headers.get(i);
if (name.equalsIgnoreCase(header.name())) {
return header;
}
}
return null;
}
@SuppressWarnings("unchecked")
public <H extends HttpHeader> H getHeader(Class<H> headerClass) {
final FingerTrieSeq<HttpHeader> headers = headers();
for (int i = 0, n = headers.size(); i < n; i += 1) {
final HttpHeader header = headers.get(i);
if (headerClass.isInstance(header)) {
return (H) header;
}
}
return null;
}
public abstract HttpMessage<T> headers(FingerTrieSeq<HttpHeader> headers);
public abstract HttpMessage<T> headers(HttpHeader... headers);
public abstract HttpMessage<T> appendedHeaders(FingerTrieSeq<HttpHeader> newHeaders);
public abstract HttpMessage<T> appendedHeaders(HttpHeader... newHeaders);
public abstract HttpMessage<T> appendedHeader(HttpHeader newHeader);
public abstract HttpMessage<T> updatedHeaders(FingerTrieSeq<HttpHeader> newHeaders);
public abstract HttpMessage<T> updatedHeaders(HttpHeader... newHeaders);
public abstract HttpMessage<T> updatedHeader(HttpHeader newHeader);
public abstract HttpEntity<T> entity();
public abstract <T2> HttpMessage<T2> entity(HttpEntity<T2> entity);
public abstract <T2> HttpMessage<T2> content(HttpEntity<T2> entity);
public abstract HttpMessage<String> body(String content, MediaType mediaType);
public abstract HttpMessage<String> body(String content);
public <T2> Decoder<? extends HttpMessage<T2>> entityDecoder(Decoder<T2> contentDecoder) {
int bodyType = 0;
long length = 0L;
final FingerTrieSeq<HttpHeader> headers = headers();
for (int i = 0, n = headers.size(); i < n; i += 1) {
final HttpHeader header = headers.get(i);
if (header instanceof ContentLength) {
if (bodyType == 0) {
length = ((ContentLength) header).length();
bodyType = 1;
} else if (bodyType == 1) {
return Decoder.error(new HttpException("conflicting Content-Length"));
} else if (bodyType == 2) {
return Decoder.error(new HttpException("conflicting Content-Length and chunked Transfer-Encoding"));
}
} else if (header instanceof TransferEncoding) {
final FingerTrieSeq<TransferCoding> codings = ((TransferEncoding) header).codings();
for (int j = 0, k = codings.size(); j < k; j += 1) {
final TransferCoding coding = codings.get(j);
if (coding.isChunked()) {
if (bodyType == 0) {
bodyType = 2;
} else if (bodyType == 1) {
return Decoder.error(new HttpException("conflicting Content-Length and chunked Transfer-Encoding"));
} else if (bodyType == 2) {
return Decoder.error(new HttpException("conflicting Transfer-Encoding"));
}
} else {
return Decoder.error(new HttpException("unsupported Transfer-Encoding: " + coding.toHttp()));
}
}
}
}
if (bodyType == 1 && length > 0L) {
return HttpBody.httpDecoder(this, contentDecoder, length);
} else if (bodyType == 2) {
return HttpChunked.httpDecoder(this, contentDecoder);
} else {
return Decoder.done(entity(HttpEntity.<T2>empty()));
}
}
@SuppressWarnings("unchecked")
public Decoder<Object> contentDecoder(MediaType mediaType) {
if (mediaType.isText()) {
return (Decoder<Object>) (Decoder<?>) Utf8.stringParser();
} else if (mediaType.isApplication()) {
if ("json".equalsIgnoreCase(mediaType.subtype)) {
return (Decoder<Object>) (Decoder<?>) Utf8.decodedParser(Json.structureParser().valueParser());
} else if ("recon".equalsIgnoreCase(mediaType.subtype)
|| "x-recon".equalsIgnoreCase(mediaType.subtype)) {
return (Decoder<Object>) (Decoder<?>) Utf8.decodedParser(Recon.structureParser().blockParser());
} else if ("xml".equalsIgnoreCase(mediaType.subtype)) {
return (Decoder<Object>) (Decoder<?>) Utf8.decodedParser(Xml.structureParser().documentParser());
}
}
return (Decoder<Object>) (Decoder<?>) Decipher.structureDecoder().anyDecoder();
}
public Decoder<Object> contentDecoder() {
final FingerTrieSeq<HttpHeader> headers = headers();
for (int i = 0, n = headers.size(); i < n; i += 1) {
final HttpHeader header = headers.get(i);
if (header instanceof ContentType) {
return contentDecoder(((ContentType) header).mediaType());
}
}
return contentDecoder(MediaType.applicationOctetStream());
}
public Encoder<?, ? extends HttpMessage<T>> httpEncoder(HttpWriter http) {
return new HttpMessageEncoder<T>(http, this);
}
public Encoder<?, ? extends HttpMessage<T>> httpEncoder() {
return httpEncoder(Http.standardWriter());
}
public Encoder<?, ? extends HttpMessage<T>> encodeHttp(OutputBuffer<?> output, HttpWriter http) {
return HttpMessageEncoder.encode(output, http, this);
}
public Encoder<?, ? extends HttpMessage<T>> encodeHttp(OutputBuffer<?> output) {
return encodeHttp(output, Http.standardWriter());
}
static FingerTrieSeq<HttpHeader> updatedHeaders(FingerTrieSeq<HttpHeader> oldHeaders, HttpHeader newHeader) {
final Builder<HttpHeader, FingerTrieSeq<HttpHeader>> headers = FingerTrieSeq.builder();
boolean updated = false;
boolean changed = false;
for (int i = 0, n = oldHeaders.size(); i < n; i += 1) {
final HttpHeader oldHeader = oldHeaders.get(i);
if (oldHeader.lowerCaseName().equals(newHeader.lowerCaseName())) {
updated = true;
if (!oldHeader.equals(newHeader)) {
changed = true;
}
headers.add(newHeader);
} else {
headers.add(oldHeader);
}
}
if (!updated) {
headers.add(newHeader);
changed = true;
}
if (changed) {
return headers.bind();
} else {
return oldHeaders;
}
}
static FingerTrieSeq<HttpHeader> updatedHeaders(FingerTrieSeq<HttpHeader> oldHeaders,
FingerTrieSeq<HttpHeader> newHeaders) {
final int newHeaderCount = newHeaders.size();
if (newHeaderCount == 0) {
return oldHeaders;
} else if (newHeaderCount == 1) {
return updatedHeaders(oldHeaders, newHeaders.head());
} else {
final Builder<HttpHeader, FingerTrieSeq<HttpHeader>> headers = FingerTrieSeq.builder();
final HashTrieSet<HttpHeader> absent = HashTrieSet.from(newHeaders);
boolean changed = false;
loop: for (int i = 0, oldHeaderCount = oldHeaders.size(); i < oldHeaderCount; i += 1) {
final HttpHeader oldHeader = oldHeaders.get(i);
for (int j = 0; j < newHeaderCount; j += 1) {
final HttpHeader newHeader = newHeaders.get(j);
if (oldHeader.lowerCaseName().equals(newHeader.lowerCaseName())) {
absent.remove(newHeader);
if (!oldHeader.equals(newHeader)) {
changed = true;
}
headers.add(newHeader);
continue loop;
}
}
headers.add(oldHeader);
}
if (!absent.isEmpty()) {
for (int j = 0; j < newHeaderCount; j += 1) {
final HttpHeader newHeader = newHeaders.get(j);
if (absent.contains(newHeader)) {
headers.add(newHeader);
changed = true;
}
}
}
if (changed) {
return headers.bind();
} else {
return oldHeaders;
}
}
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpMessageEncoder.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.http;
import swim.codec.Encoder;
import swim.codec.EncoderException;
import swim.codec.OutputBuffer;
import swim.codec.Utf8;
import swim.codec.Writer;
final class HttpMessageEncoder<T> extends Encoder<Object, HttpMessage<T>> {
final HttpWriter http;
final HttpMessage<T> message;
final Object part;
final int step;
HttpMessageEncoder(HttpWriter http, HttpMessage<T> message, Object part, int step) {
this.http = http;
this.message = message;
this.part = part;
this.step = step;
}
HttpMessageEncoder(HttpWriter http, HttpMessage<T> message) {
this(http, message, null, 1);
}
public Encoder<Object, HttpMessage<T>> pull(OutputBuffer<?> output) {
return encode(output, this.http, this.message, this.part, this.step);
}
@SuppressWarnings("unchecked")
static <T> Encoder<Object, HttpMessage<T>> encode(OutputBuffer<?> output, HttpWriter http,
HttpMessage<T> message, Object part, int step) {
if (step == 1) {
if (part == null) {
part = Utf8.writeEncoded(message.httpWriter(http), output);
} else {
part = ((Writer<?, ?>) part).pull(output);
}
final Writer<?, ?> writer = (Writer<?, ?>) part;
if (writer.isDone()) {
part = null;
step = 2;
} else if (writer.isError()) {
return error(writer.trap());
}
}
if (step == 2) {
if (part == null) {
part = message.entity().encodeHttp(message, output, http);
} else {
part = ((Encoder<?, ?>) part).pull(output);
}
final Encoder<?, HttpMessage<T>> encoder = (Encoder<?, HttpMessage<T>>) part;
if (encoder.isDone()) {
return encoder.asDone();
} else if (encoder.isError()) {
return encoder.asError();
}
}
if (output.isDone()) {
return error(new EncoderException("truncated"));
} else if (output.isError()) {
return error(output.trap());
}
return new HttpMessageEncoder<T>(http, message, part, step);
}
static <T> Encoder<Object, HttpMessage<T>> encode(OutputBuffer<?> output, HttpWriter http,
HttpMessage<T> message) {
return encode(output, http, message, null, 1);
}
}
|
0 | java-sources/ai/swim/swim-http/3.10.0/swim | java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpMethod.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.http;
import swim.codec.Debug;
import swim.codec.Format;
import swim.codec.Output;
import swim.codec.Writer;
import swim.util.Murmur3;
public final class HttpMethod extends HttpPart implements Debug {
final String name;
HttpMethod(String name) {
this.name = name;
}
public String name() {
return this.name;
}
@Override
public Writer<?, ?> httpWriter(HttpWriter http) {
return http.methodWriter(this.name);
}
@Override
public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) {
return http.writeMethod(this.name, output);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof HttpMethod) {
final HttpMethod that = (HttpMethod) other;
return this.name.equals(that.name);
}
return false;
}
@Override
public int hashCode() {
if (hashSeed == 0) {
hashSeed = Murmur3.seed(HttpMethod.class);
}
return Murmur3.mash(Murmur3.mix(hashSeed, this.name.hashCode()));
}
@Override
public void debug(Output<?> output) {
output = output.write("HttpMethod").write('.');
if (this.name.equals("GET") || this.name.equals("HEAD") || this.name.equals("POST")
|| this.name.equals("PUT") || this.name.equals("DELETE") || this.name.equals("CONNECT")
|| this.name.equals("OPTIONS") || this.name.equals("TRACE")) {
output = output.write(name);
} else {
output = output.write("from").write('(').debug(this.name).write(')');
}
}
@Override
public String toString() {
return Format.debug(this);
}
private static int hashSeed;
public static final HttpMethod GET = new HttpMethod("GET");
public static final HttpMethod HEAD = new HttpMethod("HEAD");
public static final HttpMethod POST = new HttpMethod("POST");
public static final HttpMethod PUT = new HttpMethod("PUT");
public static final HttpMethod DELETE = new HttpMethod("DELETE");
public static final HttpMethod CONNECT = new HttpMethod("CONNECT");
public static final HttpMethod OPTIONS = new HttpMethod("OPTIONS");
public static final HttpMethod TRACE = new HttpMethod("TRACE");
public static HttpMethod from(String name) {
if (name.equals("GET")) {
return GET;
} else if (name.equals("HEAD")) {
return HEAD;
} else if (name.equals("POST")) {
return POST;
} else if (name.equals("PUT")) {
return PUT;
} else if (name.equals("DELETE")) {
return DELETE;
} else if (name.equals("CONNECT")) {
return CONNECT;
} else if (name.equals("OPTIONS")) {
return OPTIONS;
} else if (name.equals("TRACE")) {
return TRACE;
} else {
return new HttpMethod(name);
}
}
public static HttpMethod parseHttp(String string) {
return Http.standardParser().parseMethodString(string);
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.