org.wegra.net
Class Server

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.wegra.net.Server
All Implemented Interfaces:
java.lang.Runnable

public class Server
extends java.lang.Thread

¹ü¿ëÀûÀÎ ¼­¹öÃø ¼ÒÄÏÀ¸·Î Ŭ¶óÀÌ¾ðÆ® °ü·Ã ÀÛ¾÷µéÀ» ÀÚü ½º·¹µå¿¡¼­ ó¸® ÇÑ´Ù. ´ÙÀ½°ú °°ÀÌ »ç¿ëÇÏ¸é µÈ´Ù.

	class ConnectionStrategy implenents ClientSocket {
		protected void communicate( Socket socket ) {
			// Ŭ¶óÀÌ¾ðÆ®¿¡ ´ëÇÑ Ä¿³Ø¼ÇÀÌ ¸Î¾îÁú ¶§¸¶´Ù È£ÃâµÈ´Ù.
			// ÀÌ ¸Þ¼Òµå´Â ÀϾ¾ß ÇÒ Åë½Å¿¡ ´ëÇÑ ¸ðµç °ÍÀ» ĸ½¶È­ÇÑ´Ù.
			// ÀÌ ¸Þ¼Òµå´Â º°µµÀÇ ½º·¹µå¿¡¼­ ½ÇÇàµÇ¸ç
			// ClientSocket °´Ã¼´Â ´ÙÀ½ Ä¿³Ø¼ÇÀ» À§ÇØ ÀçȰ¿ëµÈ´Ù.
			// µû¶ó¼­, ClientSocket °´Ã¼´Â ¾ðÁ¦³ª communicate() ¸Þ¼Òµå
			//°¡Àå óÀ½¿¡ ÃʱâÈ­µÇ¾î¾ß ÇÑ´Ù.
		}

		public Object replicate() {
			return new ConnectionStrategy();
		}
	};

	Server echoServer = new Server( portNumber,
									expectedConnectionCount,
									new ConnectionStrategy(),
									new SocketServer.Death);
 

Version:
1.0 (2001-08-31)
Author:
wegra (Bok-yeon Lee)

Nested Class Summary
static class Server.Test
          Å×½ºÆ®¿ë Ŭ·¡½º.
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Server(int portNumber, int expectedConnections, Client connectionStrategy, ShutdownOperation shutdownStrategy)
          ¼­¹ö ¼ÒÄÏ ½º·¹µå¸¦ ¸¸µé°Å ¼­¹ö ¼ÒÄÏÀ» ¸¸µé¾î À¯ÁöÇÑ´Ù.
 
Method Summary
 void kill()
          SocketServer ½º·¹µå¸¦ ¾ÈÀüÇÏ°Ô Á¾·á½ÃŲ´Ù.
 void run()
          "accept" ¼øÈ¯¹®À» ±¸ÇöÇÑ´Ù.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Server

public Server(int portNumber,
              int expectedConnections,
              Client connectionStrategy,
              ShutdownOperation shutdownStrategy)
       throws java.lang.InstantiationException
¼­¹ö ¼ÒÄÏ ½º·¹µå¸¦ ¸¸µé°Å ¼­¹ö ¼ÒÄÏÀ» ¸¸µé¾î À¯ÁöÇÑ´Ù. Ŭ¶óÀÌ¾ðÆ®°¡ Á¢¼ÓÇÏ¸é °¢ Ŭ¶óÀÌ¾ðÆ® º°·Î ½º·¹µå¿¡ µð½ºÆÐÄ¡ ÇØÁØ´Ù.

Parameters:
portNumber - ¼­¹ö ¼ÒÄÏÀÇ Æ÷Æ® ¹øÈ£
expectedConnections - ¿¹»óµÇ´Â µ¿½Ã Á¢¼ÓÀÚ ¼ö ¿©±â¼­ ÁöÁ¤ÇÏ´Â °ªº¸´Ù ¸¹Àº Ä¿³Ø¼ÇÀ» ó¸®ÇÒ ¼ö´Â ÀÖÁö¸¸ ÀÌ °æ¿ì Ŭ¶óÀÌ¾ðÆ®°¡ Á¢¼ÓµÉ ¶§ »õ·Ó°Ô ½º·¹µå¸¦ ¸¸µé¾î¾ß ÇÑ´Ù.
connectionStrategy - ClientSocket À» »ó¼Ó¹Þ´Â Ŭ·¡½ºÀÇ ÀνºÅϽº ¸¦ ³Ö¾îÁÖ¸é µÇ¸ç ¿©±â¿¡¼­´Â °¢ Ŭ¶óÀÌ¾ðÆ® Ä¿³Ø¼Ç¿¡¼­ ÇØ¾ßÇÒ ÀϵéÀ» ĸ½¶È­ÇÑ´Ù. ÀÌ °´Ã¼´Â Çʿ信 µû¶ó º¹Á¦µÇ¸ç ÀÌ·¯ÇÑ º¹Á¦´Â GoF Ã¥ÀÇ ÇÁ·ÎÅäŸÀÔ ÆÐÅÏÀ» Àû¿ëÇÑ °ÍÀÌ´Ù. Áï, connectionStrategy °´Ã¼´Â ½ÇÁ¦·Î »ç¿ëµÉ °´Ã¼¿¡ ´ëÇÑ ÇÁ·ÎÅäŸÀÔÀÎ ¼ÀÀÌ´Ù.
shutdownStrategy - ShutdownOperation Àº ¼­¹ö ½º·¹µå°¡ Á¾·áµÉ ¶§ ÇÒ ÀÏÀ» ĸ½¶È­ÇÑ´Ù(kill() ¿¡ ÀÇÇØ Á¾·áµÇ°Å³ª ³»ºÎÀûÀ¸·Î Á¾·áµÇ´Â °æ¿ì ¸ðµÎ ½ÇÇàµÈ´Ù).
Throws:
java.lang.InstantiationError - ¸¸¾à °´Ã¼°¡ ¾î¶°ÇÑ ÀÌÀ¯¿¡¼­°Ç ¼º°øÀûÀ¸·Î »ý¼ºµÇÁö ¸øÇß´Ù¸é ¹ß»ýÇÑ´Ù(¼ÒÄÏÀÌ ¿­¸®Áö ¸øÇϰųª Ŭ¶óÀ̾ðÆ®ÀÇ ÀÛ¾÷ÀÌ »ý¼ºµÉ ¼ö ¾øÀ» °æ¿ì µî). ¹ß»ýÇÑ´Ù.
java.lang.InstantiationException
Method Detail

kill

public final void kill()
SocketServer ½º·¹µå¸¦ ¾ÈÀüÇÏ°Ô Á¾·á½ÃŲ´Ù. °ü·ÃµÈ ¸ðµç ½º·¹µå°¡ °°ÀÌ Á¾·áµÈ´Ù(ÇÏÁö¸¸ ÇöÀç ¼­ºñ½º ÁßÀΠŬ¶ó¸®¾ðÆ® ½º·¹µåµéÀº ¼­ºñ½º¸¦ ¸¶Ä¥ ¶§ ±îÁö ±×´ë·Î ³²¾Æ Ȱ¼º »óÅ·ΠÀ¯ÁöµÈ´Ù). ¸ÞÀÎ ¼ÒÄϵµ Á¾·áµÈ´Ù.


run

public void run()
"accept" ¼øÈ¯¹®À» ±¸ÇöÇÑ´Ù. ¿©±â¾î¼¼´Â Ŭ¶óÀÌ¾ðÆ®°¡ Á¢¼ÓÇÒ ¶§±îÁö ±â´Ù¸®´Ù°¡ Ŭ¶óÀÌ¾ðÆ®°¡ Á¢¼ÓÇϸé ClientSocket ÇÁ·ÎÅäŸÀÔÀ» º¹Á¦Çϰí ÀÌ °´Ã¼ÀÇ communicate() ¸Þ¼Òµå¸¦ È£ÃâÇÑ´Ù. ÀÌ ¸Þ¼Òµå´Â ³»ºÎÀûÀÎ ÀÚü ½º·¹µå¿¡¼­ ½ÇÇàµÈ´Ù. ¸¸¾à ¾î¶°ÇÑ ÀÌÀ¯¿¡ ÀÇÇØ accept() °¡ ½ÇÆÐÇÑ´Ù¸é ½º·¹µå´Â Á¾·áµÇ¸ç »ý¼ºÀÚ·Î ³Ñ±ä shutdownStrategy °¡ ½ÇÇàµÈ´Ù.