BAEL-393: renamed guice-intro directory to guice (#1385)
* Add files via upload * Update pom.xml * Update RunGuice.java * Update Communication.java * Update CommunicationMode.java * Update DefaultCommunicator.java * Update EmailCommunicationMode.java * Update IMCommunicationMode.java * Update SMSCommunicationMode.java * Update MessageLogger.java * Update MessageSentLoggable.java * Update AOPModule.java * Update BasicModule.java * Update CommunicationModel.java * Update Communicator.java * Update BasicModule.java * Update RunGuice.java * Update MessageLogger.java * Update Communicator.java * Update pom.xml * BAEL-278: Updated README.md * BAEL-554: Add and update README.md files * Update pom.xml * Update pom.xml * Update pom.xml * BAEL-345: fixed assertion * BAEL-109: Updated README.md * BAEL-345: Added README.md * Reinstating reactor-core module in root-level pom * BAEL-393: Adding guide-intro module to root pom * BAEL-9: Updated README.md * BAEL-157: README.md updated * Changed project name * Update RunGuice.java Removed references to message logging and output * Update Communication.java Removed message logging-related code * BAEL-566: Updated README.md * New project name * BAEL-393: removing guice-intro directory * BAEL-393: renamed module guice-intro to guice in root pom.xml
This commit is contained in:
parent
d32d3edcc9
commit
4a773e79cd
|
@ -1,11 +0,0 @@
|
|||
package com.baeldung.examples.guice.marker;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Baeldung
|
||||
*/
|
||||
public interface Communicator {
|
||||
|
||||
public boolean sendMessage(String message);
|
||||
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung.examples.guice</groupId>
|
||||
<artifactId>guice-intro</artifactId>
|
||||
<artifactId>guice</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
|
@ -30,5 +30,5 @@
|
|||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<guice.version>4.1.0</guice.version>
|
||||
</properties>
|
||||
<name>guice-intro</name>
|
||||
<name>guice</name>
|
||||
</project>
|
|
@ -10,7 +10,7 @@ import java.util.Scanner;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author Baeldung
|
||||
* @author baeldung
|
||||
*/
|
||||
public class RunGuice {
|
||||
|
||||
|
@ -18,14 +18,10 @@ public class RunGuice {
|
|||
Injector injector = Guice.createInjector(new BasicModule(), new AOPModule());
|
||||
Communication comms = injector.getInstance(Communication.class);
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.println("Enter your message to be sent; press Q to quit and P to print the message log");
|
||||
while (true) {
|
||||
String input = scanner.nextLine();
|
||||
if (input.equalsIgnoreCase("q")) {
|
||||
System.exit(0);
|
||||
}
|
||||
if (input.equalsIgnoreCase("p")) {
|
||||
comms.print();
|
||||
} else {
|
||||
comms.sendMessage(input);
|
||||
}
|
|
@ -10,7 +10,7 @@ import java.util.logging.Logger;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author Baeldung
|
||||
* @author baeldung
|
||||
*/
|
||||
public class Communication {
|
||||
|
||||
|
@ -19,37 +19,20 @@ public class Communication {
|
|||
@Inject
|
||||
private Logger logger;
|
||||
|
||||
private Queue<String> messageLog;
|
||||
|
||||
@Named("CommsUUID")
|
||||
private String commsID;
|
||||
|
||||
@Inject
|
||||
private DefaultCommunicator communicator;
|
||||
|
||||
public Communication(Boolean keepRecords) {
|
||||
if (keepRecords) {
|
||||
messageLog = new LinkedList();
|
||||
System.out.println("keeping records");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean sendMessage(String message) {
|
||||
if (!message.isEmpty() && messageLog != null) {
|
||||
messageLog.add(message);
|
||||
}
|
||||
|
||||
return communicator.sendMessage(message);
|
||||
}
|
||||
|
||||
public void print() {
|
||||
if (messageLog != null) {
|
||||
for (String message : messageLog) {
|
||||
logger.info(message);
|
||||
}
|
||||
} else {
|
||||
logger.info("Message logging wasn't enabled");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DefaultCommunicator getCommunicator() {
|
||||
return this.communicator;
|
||||
}
|
|
@ -5,7 +5,10 @@ import com.baeldung.examples.guice.marker.Communicator;
|
|||
import com.google.inject.Inject;
|
||||
import com.google.inject.name.Named;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author baeldung
|
||||
*/
|
||||
public class DefaultCommunicator implements Communicator {
|
||||
|
||||
private CommunicationMode defaultCommsMode;
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
package com.baeldung.examples.guice;
|
||||
|
||||
import com.baeldung.examples.guice.aop.MessageSentLoggable;
|
||||
|
@ -5,7 +6,7 @@ import com.baeldung.examples.guice.constant.CommunicationModel;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author Baekdung
|
||||
* @author baeldung
|
||||
*/
|
||||
public class EmailCommunicationMode implements CommunicationMode {
|
||||
|
|
@ -8,7 +8,7 @@ import java.util.logging.Logger;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author Baeldung
|
||||
* @author baeldung
|
||||
*/
|
||||
public class IMCommunicationMode implements CommunicationMode {
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
package com.baeldung.examples.guice;
|
||||
|
||||
import com.baeldung.examples.guice.aop.MessageSentLoggable;
|
||||
|
@ -7,7 +8,7 @@ import java.util.logging.Logger;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author Baeldung
|
||||
* @author baeldung
|
||||
*/
|
||||
public class SMSCommunicationMode implements CommunicationMode {
|
||||
|
|
@ -1,12 +1,14 @@
|
|||
|
||||
package com.baeldung.examples.guice.aop;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import java.util.logging.Logger;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Baeldung
|
||||
* @author baeldung
|
||||
*/
|
||||
public class MessageLogger implements MethodInterceptor {
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
package com.baeldung.examples.guice.aop;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
|
@ -7,7 +8,7 @@ import java.lang.annotation.Target;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author Baeldung
|
||||
* @author baeldung
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
package com.baeldung.examples.guice.binding;
|
||||
|
||||
import com.baeldung.examples.guice.aop.MessageLogger;
|
||||
|
@ -7,7 +8,7 @@ import com.google.inject.matcher.Matchers;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author Baeldung
|
||||
* @author baeldung
|
||||
*/
|
||||
public class AOPModule extends AbstractModule {
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
package com.baeldung.examples.guice.binding;
|
||||
|
||||
import com.baeldung.examples.guice.Communication;
|
||||
|
@ -13,7 +14,7 @@ import java.util.logging.Logger;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author Baeldung
|
||||
* @author baeldung
|
||||
*/
|
||||
public class BasicModule extends AbstractModule {
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
|
||||
package com.baeldung.examples.guice.constant;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Baeldung
|
||||
* @author baeldung
|
||||
*/
|
||||
public enum CommunicationModel {
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.baeldung.examples.guice.marker;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Tayo
|
||||
*/
|
||||
public interface Communicator {
|
||||
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
package com.baeldung.examples.guice.modules;
|
||||
|
||||
import com.baeldung.examples.guice.Communication;
|
||||
|
@ -13,7 +14,7 @@ import java.util.logging.Logger;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author Baeldung
|
||||
* @author baeldung
|
||||
*/
|
||||
public class BasicModule extends AbstractModule {
|
||||
|
Loading…
Reference in New Issue