-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
289b8bc
commit b867aa9
Showing
10 changed files
with
293 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.homeclimatecontrol.hcc.meta.EndpointMeta; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.config.RequestConfig; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
|
@@ -18,14 +17,14 @@ | |
* | ||
* @author Copyright © <a href="mailto:[email protected]">Vadim Tkachenko</a> 2001-2024 | ||
*/ | ||
public class HccHttpClient { | ||
public class HttpClient { | ||
|
||
private final Logger logger = LogManager.getLogger(); | ||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
private HttpClient httpClient; | ||
private org.apache.http.client.HttpClient httpClient; | ||
|
||
private synchronized HttpClient getHttpClient() { | ||
private synchronized org.apache.http.client.HttpClient getHttpClient() { | ||
|
||
if (httpClient == null) { | ||
|
||
|
@@ -37,7 +36,7 @@ private synchronized HttpClient getHttpClient() { | |
return httpClient; | ||
} | ||
|
||
private HttpClient createClient() { | ||
private org.apache.http.client.HttpClient createClient() { | ||
|
||
// VT: NOTE: Copypasted with abbreviations from HttpClientFactory (search the whole project). | ||
// Important fact not to forget: https://github.com/home-climate-control/dz/issues/80 | ||
|
61 changes: 61 additions & 0 deletions
61
app/hcc-cli/src/main/java/com/homeclimatecontrol/hcc/client/rsocket/RSocketClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.homeclimatecontrol.hcc.client.rsocket; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.netty.buffer.ByteBufAllocator; | ||
import io.netty.buffer.ByteBufUtil; | ||
import io.rsocket.core.RSocketConnector; | ||
import io.rsocket.metadata.TaggingMetadataCodec; | ||
import io.rsocket.metadata.WellKnownMimeType; | ||
import io.rsocket.transport.netty.client.TcpClientTransport; | ||
import io.rsocket.util.ByteBufPayload; | ||
import net.sf.dz3r.signal.hvac.ZoneStatus; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* HCC remote client using RSocket protocol. | ||
* | ||
* @author Copyright © <a href="mailto:[email protected]">Vadim Tkachenko</a> 2001-2024 | ||
*/ | ||
public class RSocketClient { | ||
|
||
private final Logger logger = LogManager.getLogger(); | ||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
public List<ZoneStatus> getZones(String bindAddress, int port, String serialization) throws JsonProcessingException { | ||
|
||
var socket = RSocketConnector | ||
.create() | ||
.metadataMimeType(WellKnownMimeType.MESSAGE_RSOCKET_ROUTING.getString()) | ||
.connect(TcpClientTransport.create(bindAddress, port)) | ||
.block(); | ||
|
||
var routeMetadata = | ||
TaggingMetadataCodec | ||
.createTaggingContent(ByteBufAllocator.DEFAULT, Collections.singletonList(serialization)); | ||
|
||
var payload = socket | ||
.requestResponse( | ||
ByteBufPayload.create( | ||
ByteBufUtil.writeUtf8(ByteBufAllocator.DEFAULT, "zones"), routeMetadata)) | ||
.log() | ||
.block(); | ||
|
||
try { | ||
|
||
var response = payload.getDataUtf8(); | ||
var zones = objectMapper.readValue(response, Map.class); | ||
|
||
logger.info("ZONES:\n{}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(zones)); | ||
|
||
return null; | ||
} finally { | ||
payload.release(); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
modules/hcc-webui/src/main/java/net/sf/dz3r/view/webui/v2/Endpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package net.sf.dz3r.view.webui.v2; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import net.sf.dz3r.model.UnitDirector; | ||
import net.sf.dz3r.view.UnitObserver; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.Map; | ||
|
||
public class Endpoint { | ||
|
||
protected final Logger logger = LogManager.getLogger(); | ||
protected final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
protected final Map<UnitDirector, UnitObserver> unit2observer; | ||
|
||
public Endpoint(Map<UnitDirector, UnitObserver> unit2observer) { | ||
this.unit2observer = unit2observer; | ||
objectMapper.registerModule(new JavaTimeModule()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.