-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DependencyInjection: created DI for server
- Loading branch information
1 parent
7a9924c
commit 4b39975
Showing
4 changed files
with
47 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
package ca.utoronto.utm.mcs; | ||
|
||
import com.sun.net.httpserver.HttpServer; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class Server { | ||
// TODO Complete This Class | ||
private HttpServer httpServer; | ||
@Inject | ||
public Server(HttpServer httpServer){ | ||
this.httpServer = httpServer; | ||
} | ||
public void createContext(String path, ReqHandler reqHandler){ | ||
this.httpServer.createContext(path, reqHandler); | ||
} | ||
public void startServer(){ | ||
this.httpServer.start(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,33 @@ | ||
package ca.utoronto.utm.mcs; | ||
|
||
import com.sun.net.httpserver.HttpServer; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
|
||
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
|
||
@Module | ||
public class ServerModule { | ||
// TODO Complete This Module | ||
@Provides | ||
public InetSocketAddress provideInetSocketAddress(){ | ||
return new InetSocketAddress("0.0.0.0", 8080); | ||
} | ||
@Provides | ||
public HttpServer provideHttpServer(InetSocketAddress inetSocketAddress) { | ||
try { | ||
HttpServer server = HttpServer.create(inetSocketAddress, 0); | ||
|
||
return server; | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
|
||
@Provides | ||
public Server provideServer(HttpServer httpServer){ | ||
return new Server(httpServer); | ||
} | ||
} |