Skip to content

Commit

Permalink
rename adapters to ports
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardWarburton committed Jan 3, 2015
1 parent f2c05f9 commit b8703ab
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 49 deletions.
Expand Up @@ -25,8 +25,7 @@

public interface MachineListener {

// TODO: decouple listening to machines from listening to profiles
ProfileListener onNewMachine(VirtualMachine machine);
void onNewMachine(VirtualMachine machine);

void onClosedMachine(VirtualMachine machine);

Expand Down
Expand Up @@ -53,7 +53,7 @@ public boolean isAgentLoaded() {
return agentLoaded;
}

public File getLogFile() {
public File getLogSource() {
return new File(userDir, "log.hpl");
}

Expand Down
Expand Up @@ -19,6 +19,7 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
**/

/**
* Core implementation for methods of discovering machines and sources of logs.
*/
Expand Down
Expand Up @@ -21,7 +21,7 @@
**/
package com.insightfullogic.honest_profiler.delivery.console;

import com.insightfullogic.honest_profiler.adapters.store.FileLogRepository;
import com.insightfullogic.honest_profiler.ports.store.FileLogRepository;
import com.insightfullogic.honest_profiler.core.Conductor;
import com.insightfullogic.honest_profiler.core.ProfileListener;
import com.insightfullogic.honest_profiler.core.filters.ProfileFilter;
Expand Down
Expand Up @@ -21,9 +21,9 @@
**/
package com.insightfullogic.honest_profiler.delivery.javafx;

import com.insightfullogic.honest_profiler.adapters.LoggerInjector;
import com.insightfullogic.honest_profiler.adapters.sources.LocalMachineSource;
import com.insightfullogic.honest_profiler.adapters.store.FileLogRepository;
import com.insightfullogic.honest_profiler.ports.LoggerInjector;
import com.insightfullogic.honest_profiler.ports.sources.LocalMachineSource;
import com.insightfullogic.honest_profiler.ports.store.FileLogRepository;
import com.insightfullogic.honest_profiler.core.Conductor;
import com.insightfullogic.honest_profiler.core.filters.ProfileFilter;
import com.insightfullogic.honest_profiler.delivery.javafx.landing.LandingViewModel;
Expand Down
Expand Up @@ -93,7 +93,7 @@ public void open(ActionEvent actionEvent) {
public void monitor(ActionEvent actionEvent) {
windowModel.display(Profile);
MachineButton selectedButton = (MachineButton) toggleMachines.getSelectedToggle();
File logFile = selectedButton.getJvm().getLogFile();
File logFile = selectedButton.getJvm().getLogSource();
try {
conductor.pipeFile(logFile, null, profileListener);
} catch (IOException e) {
Expand All @@ -102,14 +102,13 @@ public void monitor(ActionEvent actionEvent) {
}

@Override
public ProfileListener onNewMachine(VirtualMachine machine) {
public void onNewMachine(VirtualMachine machine) {
Platform.runLater(() -> {
ObservableList<Node> children = landingView.getChildren();
MachineButton button = new MachineButton(machine);
button.setToggleGroup(toggleMachines);
children.add(button);
});
return null;
}

@Override
Expand Down
Expand Up @@ -22,9 +22,9 @@
package com.insightfullogic.honest_profiler.delivery.web;

import app.Root;
import com.insightfullogic.honest_profiler.adapters.sources.LocalMachineSource;
import com.insightfullogic.honest_profiler.adapters.sources.WebSocketMachineSource;
import com.insightfullogic.honest_profiler.adapters.store.FileLogRepository;
import com.insightfullogic.honest_profiler.ports.sources.LocalMachineSource;
import com.insightfullogic.honest_profiler.ports.sources.WebSocketMachineSource;
import com.insightfullogic.honest_profiler.ports.store.FileLogRepository;
import com.insightfullogic.honest_profiler.core.Conductor;
import com.insightfullogic.honest_profiler.core.collector.LogCollector;
import com.insightfullogic.honest_profiler.core.parser.LogParser;
Expand Down Expand Up @@ -71,7 +71,7 @@ public static MutablePicoContainer registerComponents() {
.addComponent(WebSocketMachineSource.class)
.addComponent(LocalMachineSource.class)
.addComponent(MessageEncoder.class)
.addComponent(MachineAdapter.class)
.addComponent(WebsocketMachineAdapter.class)
.addComponent(WebProfileAdapter.class)
.addComponent(ClientConnections.class)
.addComponent(ClientHandler.class)
Expand Down
Expand Up @@ -23,21 +23,20 @@

import com.insightfullogic.honest_profiler.core.MachineListener;
import com.insightfullogic.honest_profiler.core.sources.VirtualMachine;
import org.slf4j.LoggerFactory;
import org.webbitserver.WebSocketConnection;

import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;

// Not thread safe
public class MachineAdapter implements MachineListener, Consumer<WebSocketConnection> {
public class WebsocketMachineAdapter implements MachineListener, Consumer<WebSocketConnection> {

private final Set<VirtualMachine> machines;
private final ClientConnections clients;
private final MessageEncoder messages;

public MachineAdapter(ClientConnections clients, MessageEncoder messages) {
public WebsocketMachineAdapter(ClientConnections clients, MessageEncoder messages) {
this.clients = clients;
this.messages = messages;
machines = new HashSet<>();
Expand All @@ -52,10 +51,10 @@ public void accept(WebSocketConnection connection) {
}

@Override
public WebProfileAdapter onNewMachine(VirtualMachine machine) {
public void onNewMachine(VirtualMachine machine) {
machines.add(machine);
clients.sendAll(messages.addJavaVirtualMachine(machine));
return new WebProfileAdapter(LoggerFactory.getLogger(WebProfileAdapter.class), machine, clients);
//return new WebProfileAdapter(LoggerFactory.getLogger(WebProfileAdapter.class), machine, clients);
}

@Override
Expand Down
Expand Up @@ -19,7 +19,7 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
**/
package com.insightfullogic.honest_profiler.adapters;
package com.insightfullogic.honest_profiler.ports;

import org.picocontainer.PicoContainer;
import org.picocontainer.injectors.FactoryInjector;
Expand Down
Expand Up @@ -19,11 +19,10 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
**/
package com.insightfullogic.honest_profiler.adapters.sources;
package com.insightfullogic.honest_profiler.ports.sources;

import com.insightfullogic.honest_profiler.core.Conductor;
import com.insightfullogic.honest_profiler.core.MachineListener;
import com.insightfullogic.honest_profiler.core.ProfileListener;
import com.insightfullogic.honest_profiler.core.ThreadedAgent;
import com.insightfullogic.honest_profiler.core.sources.VirtualMachine;
import com.sun.tools.attach.AttachNotSupportedException;
Expand Down Expand Up @@ -65,7 +64,7 @@ public void start() {
threadedAgent.start();
}

public boolean discoverVirtualMachines() {
private boolean discoverVirtualMachines() {
poll();

sleep();
Expand All @@ -81,18 +80,9 @@ private void sleep() {
}
}

public void poll() {
private void poll() {
Set<VirtualMachineDescriptor> current = new HashSet<>(com.sun.tools.attach.VirtualMachine.list());
difference(current, previous, machine -> {
ProfileListener profileListener = listener.onNewMachine(machine);
if (machine.isAgentLoaded() && profileListener != null) {
try {
conductor.pipeFile(machine.getLogFile(), machine, profileListener);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
});
difference(current, previous, listener::onNewMachine);
difference(previous, current, listener::onClosedMachine);
previous = current;
}
Expand Down
Expand Up @@ -19,13 +19,12 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
**/
package com.insightfullogic.honest_profiler.adapters.sources;
package com.insightfullogic.honest_profiler.ports.sources;

import com.google.protobuf.InvalidProtocolBufferException;
import com.insightfullogic.honest_profiler.core.Conductor;
import com.insightfullogic.honest_profiler.core.DataConsumer;
import com.insightfullogic.honest_profiler.core.MachineListener;
import com.insightfullogic.honest_profiler.core.ProfileListener;
import com.insightfullogic.honest_profiler.core.sources.VirtualMachine;
import org.slf4j.Logger;
import org.webbitserver.BaseWebSocketHandler;
Expand Down Expand Up @@ -80,11 +79,11 @@ private void newMachine(WebSocketConnection connection, byte[] message) {
try {
Messages.NewMachine newMachine = Messages.NewMachine.parseFrom(message);
VirtualMachine machine = new VirtualMachine(newMachine.getId(), newMachine.getDisplayName(), true, "");
ProfileListener profileListener = listener.onNewMachine(machine);
/*ProfileListener profileListener = listener.onNewMachine(machine);
if (profileListener != null) {
DataConsumer consumer = conductor.pipeData(machine, profileListener);
machines.put(connection, consumer);
}
}*/
} catch (InvalidProtocolBufferException e) {
logger.error(e.getMessage(), e);
}
Expand Down
Expand Up @@ -22,5 +22,5 @@
/**
* Infrastructure for methods of discovering machines and sources of logs.
*/
package com.insightfullogic.honest_profiler.adapters.sources;
package com.insightfullogic.honest_profiler.ports.sources;

Expand Up @@ -19,7 +19,7 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
**/
package com.insightfullogic.honest_profiler.adapters.store;
package com.insightfullogic.honest_profiler.ports.store;

import com.insightfullogic.honest_profiler.core.sources.VirtualMachine;
import com.insightfullogic.honest_profiler.core.store.LogMetadata;
Expand Down
Expand Up @@ -19,7 +19,7 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
**/
package com.insightfullogic.honest_profiler.adapters.store;
package com.insightfullogic.honest_profiler.ports.store;

import com.insightfullogic.honest_profiler.core.store.LogSaver;

Expand Down
2 changes: 1 addition & 1 deletion src/main/proto/messages.proto
@@ -1,6 +1,6 @@
package tutorial;

option java_package = "com.insightfullogic.honest_profiler.adapters.sources";
option java_package = "com.insightfullogic.honest_profiler.ports.sources";
option java_outer_classname = "Messages";

message NewMachine {
Expand Down
Expand Up @@ -30,17 +30,17 @@
import static org.mockito.Mockito.verify;

@RunWith(JunitSuiteRunner.class)
public class VirtualMachineAdapterTest {
public class VirtualWebsocketMachineAdapterTest {

ClientConnections clients;
VirtualMachine jvm = new VirtualMachine("12432", "com.intellij.idea.Main", true, "");
MachineAdapter adapter;
WebsocketMachineAdapter adapter;

{ describe("The Java Virtual Machine Adapter", it -> {

it.isSetupWith(() -> {
clients = Mockito.mock(ClientConnections.class);
adapter = new MachineAdapter(clients, new MessageEncoder());
adapter = new WebsocketMachineAdapter(clients, new MessageEncoder());
});

it.should("Register for connections", expect -> {
Expand Down
Expand Up @@ -19,10 +19,10 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
**/
package com.insightfullogic.honest_profiler.adapters;
package com.insightfullogic.honest_profiler.ports;

import com.insightfullogic.honest_profiler.adapters.sources.Messages;
import com.insightfullogic.honest_profiler.adapters.sources.WebSocketMachineSource;
import com.insightfullogic.honest_profiler.ports.sources.Messages;
import com.insightfullogic.honest_profiler.ports.sources.WebSocketMachineSource;
import com.insightfullogic.honest_profiler.core.Conductor;
import com.insightfullogic.honest_profiler.core.DataConsumer;
import com.insightfullogic.honest_profiler.core.MachineListener;
Expand Down Expand Up @@ -64,7 +64,6 @@ public class WebSocketMachineSourceTest {
reset(connection, dataConsumer, conductor, listener);
when(conductor.pipeData(any(), any())).thenReturn(dataConsumer);
when(dataConsumer.getMachine()).thenReturn(machine);
when(listener.onNewMachine(any())).thenReturn(profileListener);

finder = new WebSocketMachineSource(logger, conductor, listener);
});
Expand Down

0 comments on commit b8703ab

Please sign in to comment.