Browse Source
* Move Request and Response to loadbalancer package. Fixes gh-772.
* Fix checkstyle.
* Inherit and reference repackaged classes.
* Revert "Inherit and reference repackaged classes."
This reverts commit 02808c5f18
.
* Fix Status enums.
* Make old classes extend the new ones.
pull/789/head
Olga Maciaszek-Sharma
4 years ago
committed by
GitHub
14 changed files with 374 additions and 83 deletions
@ -0,0 +1,70 @@
@@ -0,0 +1,70 @@
|
||||
/* |
||||
* Copyright 2012-2020 the original author or authors. |
||||
* |
||||
* 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 |
||||
* |
||||
* https://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 org.springframework.cloud.client.loadbalancer; |
||||
|
||||
import org.springframework.core.style.ToStringCreator; |
||||
|
||||
/** |
||||
* @author Spencer Gibb |
||||
*/ |
||||
// TODO: add metrics
|
||||
public class CompletionContext { |
||||
|
||||
private final Status status; |
||||
|
||||
private final Throwable throwable; |
||||
|
||||
public CompletionContext(Status status) { |
||||
this(status, null); |
||||
} |
||||
|
||||
public CompletionContext(Status status, Throwable throwable) { |
||||
this.status = status; |
||||
this.throwable = throwable; |
||||
} |
||||
|
||||
public Status status() { |
||||
return this.status; |
||||
} |
||||
|
||||
public Throwable getThrowable() { |
||||
return this.throwable; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
ToStringCreator to = new ToStringCreator(this); |
||||
to.append("status", this.status); |
||||
to.append("throwable", this.throwable); |
||||
return to.toString(); |
||||
} |
||||
|
||||
/** |
||||
* Request status state. |
||||
*/ |
||||
public enum Status { |
||||
|
||||
/** Request was handled successfully. */ |
||||
SUCCESS, |
||||
/** Request reached the server but failed due to timeout or internal error. */ |
||||
FAILED, |
||||
/** Request did not go off box and should not be counted for statistics. */ |
||||
DISCARD, |
||||
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
/* |
||||
* Copyright 2012-2020 the original author or authors. |
||||
* |
||||
* 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 |
||||
* |
||||
* https://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 org.springframework.cloud.client.loadbalancer; |
||||
|
||||
/** |
||||
* A default implementation of {@link Request}. |
||||
* |
||||
* @author Spencer Gibb |
||||
* @author Olga Maciaszek-Sharma |
||||
*/ |
||||
public class DefaultRequest<T> implements Request<T> { |
||||
|
||||
private T context; |
||||
|
||||
public DefaultRequest() { |
||||
new DefaultRequestContext(); |
||||
} |
||||
|
||||
public DefaultRequest(T context) { |
||||
this.context = context; |
||||
} |
||||
|
||||
@Override |
||||
public T getContext() { |
||||
return context; |
||||
} |
||||
|
||||
public void setContext(T context) { |
||||
this.context = context; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
/* |
||||
* Copyright 2012-2020 the original author or authors. |
||||
* |
||||
* 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 |
||||
* |
||||
* https://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 org.springframework.cloud.client.loadbalancer; |
||||
|
||||
/** |
||||
* Contains information relevant to the request. |
||||
* |
||||
* @author Olga Maciaszek-Sharma |
||||
*/ |
||||
public class DefaultRequestContext { |
||||
|
||||
/** |
||||
* A {@link String} value of hint that can be used to choose the correct service |
||||
* instance. |
||||
*/ |
||||
private String hint = "default"; |
||||
|
||||
public DefaultRequestContext() { |
||||
} |
||||
|
||||
public DefaultRequestContext(String hint) { |
||||
this.hint = hint; |
||||
} |
||||
|
||||
public String getHint() { |
||||
return hint; |
||||
} |
||||
|
||||
public void setHint(String hint) { |
||||
this.hint = hint; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
/* |
||||
* Copyright 2012-2020 the original author or authors. |
||||
* |
||||
* 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 |
||||
* |
||||
* https://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 org.springframework.cloud.client.loadbalancer; |
||||
|
||||
import org.springframework.cloud.client.ServiceInstance; |
||||
|
||||
/** |
||||
* @author Spencer Gibb |
||||
*/ |
||||
public class DefaultResponse implements Response<ServiceInstance> { |
||||
|
||||
private final ServiceInstance serviceInstance; |
||||
|
||||
public DefaultResponse(ServiceInstance serviceInstance) { |
||||
this.serviceInstance = serviceInstance; |
||||
} |
||||
|
||||
@Override |
||||
public boolean hasServer() { |
||||
return this.serviceInstance != null; |
||||
} |
||||
|
||||
@Override |
||||
public ServiceInstance getServer() { |
||||
return this.serviceInstance; |
||||
} |
||||
|
||||
@Override |
||||
public void onComplete(CompletionContext completionContext) { |
||||
// TODO: implement
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
/* |
||||
* Copyright 2012-2020 the original author or authors. |
||||
* |
||||
* 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 |
||||
* |
||||
* https://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 org.springframework.cloud.client.loadbalancer; |
||||
|
||||
import org.springframework.cloud.client.ServiceInstance; |
||||
|
||||
/** |
||||
* @author Spencer Gibb |
||||
*/ |
||||
public class EmptyResponse implements Response<ServiceInstance> { |
||||
|
||||
@Override |
||||
public boolean hasServer() { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public ServiceInstance getServer() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void onComplete(CompletionContext completionContext) { |
||||
// TODO: implement
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
/* |
||||
* Copyright 2012-2020 the original author or authors. |
||||
* |
||||
* 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 |
||||
* |
||||
* https://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 org.springframework.cloud.client.loadbalancer; |
||||
|
||||
/** |
||||
* Marker interface for a request. |
||||
* |
||||
* @author Spencer Gibb |
||||
* @author Olga Maciaszek-Sharma |
||||
*/ |
||||
public interface Request<C> { |
||||
|
||||
// Avoid breaking backward compatibility
|
||||
default C getContext() { |
||||
return null; |
||||
} |
||||
|
||||
// TODO: define contents
|
||||
|
||||
} |
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
/* |
||||
* Copyright 2012-2020 the original author or authors. |
||||
* |
||||
* 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 |
||||
* |
||||
* https://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 org.springframework.cloud.client.loadbalancer; |
||||
|
||||
/** |
||||
* Response created for each request. |
||||
* |
||||
* @param <T> type of the server |
||||
* @author Spencer Gibb |
||||
*/ |
||||
public interface Response<T> { |
||||
|
||||
boolean hasServer(); |
||||
|
||||
T getServer(); |
||||
|
||||
/** |
||||
* Notification that the request completed. |
||||
* @deprecated <code>onComplete</code> callbacks for load-balanced calls are being |
||||
* moved to a separate interface |
||||
* @param completionContext - completion context |
||||
*/ |
||||
@Deprecated |
||||
void onComplete(CompletionContext completionContext); |
||||
|
||||
} |
Loading…
Reference in new issue