1 2 3 package com.db4odoc.f1.semaphores; 4 5 6 import java.io.*; 7 import com.db4o.*; 8 9 13 public class LimitLogins { 14 15 static final String HOST = "localhost"; 16 static final int PORT = 4455; 17 static final String USER = "db4o"; 18 static final String PASSWORD = "db4o"; 19 20 static final int MAXIMUM_USERS = 10; 21 22 public static ObjectContainer login(){ 23 24 ObjectContainer objectContainer; 25 try { 26 objectContainer = Db4o.openClient(HOST, PORT, USER, PASSWORD); 27 } catch (IOException e) { 28 return null; 29 } 30 31 boolean allowedToLogin = false; 32 33 for (int i = 0; i < MAXIMUM_USERS; i++) { 34 if(objectContainer.ext().setSemaphore("max_user_check_" + i, 0)){ 35 allowedToLogin = true; 36 break; 37 } 38 } 39 40 if(! allowedToLogin){ 41 objectContainer.close(); 42 return null; 43 } 44 45 return objectContainer; 46 } 47 } 48 | Popular Tags |