Example usage for com.amazonaws.regions Region getRegion

List of usage examples for com.amazonaws.regions Region getRegion

Introduction

In this page you can find the example usage for com.amazonaws.regions Region getRegion.

Prototype

public static Region getRegion(Regions region) 

Source Link

Document

Returns the region with the id given, or null if it cannot be found in the current regions.xml file.

Usage

From source file:edu.columbia.cc.elPonePeli.app.LiveStreamingHelper.java

public LiveStreamingHelper(AWSCredentials credentials) {
    stackbuilder = new AmazonCloudFormationClient(credentials);
    Region region = Region.getRegion(Regions.US_EAST_1);
    stackbuilder.setRegion(region);//from w  w w.ja va2  s  .  c  o  m

    System.out.println("===========================================");
    System.out.println("Starting Live Streaming Formation");
    System.out.println("===========================================\n");

    String logicalResourceName = "SampleNotificationTopic";
    createFormation(streamingStackName, logicalResourceName);
}

From source file:edu.iu.finch.core.NexRad.java

License:Apache License

private void init(AWSCredentials credentials) {
    s3Client = new AmazonS3Client(credentials);
    Region region = Region.getRegion(Regions.US_EAST_1);
    s3Client.setRegion(region);/*from w w  w .j  a va  2 s. c o m*/
}

From source file:edu.rutgers.winlab.crowdpp.service.SpeakerCountService.java

License:Open Source License

@Override
public void onCreate() {
    Toast.makeText(this, "Speaker Count Service Started ", Toast.LENGTH_SHORT).show();
    serviceDir = new File(Constants.servicePath);
    showInfo();// w ww  .ja  va2 s  . c o m
    if (!serviceDir.exists() || !serviceDir.isDirectory()) {
        serviceDir.mkdir();
    }

    mDatabase = new DataBaseHelper(getApplicationContext());
    mDB = mDatabase.getWritableDatabase();

    loc = new LocationTracker(getApplicationContext());

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "No sleep");
    wl.acquire();

    s3Client = new AmazonS3Client(new BasicAWSCredentials(Constants.ACCESS_KEY_ID, Constants.SECRET_KEY));
    s3Client.setRegion(Region.getRegion(Regions.US_WEST_2));
}

From source file:edu.rutgers.winlab.crowdpp.ui.HomeFragment.java

License:Open Source License

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.home_fragment_layout, container, false);

    tb_cal = (ToggleButton) view.findViewById(R.id.tb_home_calibration);
    tb_service = (ToggleButton) view.findViewById(R.id.tb_home_service);
    tb_test = (ToggleButton) view.findViewById(R.id.tb_home_test);
    tv_cal_content = (TextView) view.findViewById(R.id.tv_home_calibration_content);
    tv_cal_text = (TextView) view.findViewById(R.id.tv_home_calibration_text);
    tv_debug = (TextView) view.findViewById(R.id.tv_home_test_debug);
    tv_record = (TextView) view.findViewById(R.id.tv_home_test_record);
    timer_cal = (Chronometer) view.findViewById(R.id.timer_calibration);
    timer_test = (Chronometer) view.findViewById(R.id.timer_test);
    rl_service = (RelativeLayout) view.findViewById(R.id.rl_home_service);
    rl_test = (RelativeLayout) view.findViewById(R.id.rl_home_test);
    if (isMyServiceRunning() == true)
        tb_service.setChecked(true);// www  .  ja va 2 s. c om

    if (Constants.calibration())
        tv_cal_content.setText("You are all set for the calibration.");

    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        Toast.makeText(getActivity(), "Can not find SD card ...", Toast.LENGTH_SHORT).show();
        getActivity().finish();
    }

    crowdppDir = new File(Constants.crowdppPath);
    if (!crowdppDir.exists() || !crowdppDir.isDirectory()) {
        crowdppDir.mkdir();
    }

    testDir = new File(Constants.testPath);
    if (!testDir.exists() || !testDir.isDirectory()) {
        testDir.mkdir();
    }

    calWavFile = crowdppDir + "/" + Constants.PHONE_ID + ".wav";

    timer_cal.setVisibility(View.INVISIBLE);
    timer_test.setVisibility(View.INVISIBLE);

    mDatabase = new DataBaseHelper(getActivity().getApplicationContext());
    mDB = mDatabase.getWritableDatabase();

    gps = new LocationTracker(getActivity().getApplicationContext());

    s3Client = new AmazonS3Client(new BasicAWSCredentials(Constants.ACCESS_KEY_ID, Constants.SECRET_KEY));
    s3Client.setRegion(Region.getRegion(Regions.US_WEST_2));

    tb_cal.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // prevent the calibration button being pressed when either and test or service is running 
            if (tb_service.isChecked()) {
                Toast.makeText(getActivity(), "Please turn off the service...", Toast.LENGTH_SHORT).show();
                tb_cal.setChecked(false);
            } else if (tb_test.isChecked()) {
                Toast.makeText(getActivity(), "Please turn off the test...", Toast.LENGTH_SHORT).show();
                tb_cal.setChecked(false);
            }
            // calibration
            else {
                if (isChecked) {
                    tv_cal_text.setText(Constants.cal_text);
                    rl_service.setVisibility(View.INVISIBLE);
                    rl_test.setVisibility(View.INVISIBLE);
                    timer_cal.setVisibility(View.VISIBLE);

                    AlertDialog dialog = new AlertDialog.Builder(getActivity()).create();
                    dialog.setTitle("Calibration");
                    dialog.setMessage(Constants.cal_dialog);
                    dialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            timer_cal.setBase(SystemClock.elapsedRealtime());
                            timer_cal.start();
                            tv_cal_content.setText("Recording your voice...");

                            Bundle mbundle = new Bundle();
                            mbundle.putString("audiopath", calWavFile);
                            Log.i("HomeFragment", "start audio recording service");

                            // delete the existing calibration data before the recalibration 
                            FileProcess.deleteFile(calWavFile);
                            FileProcess.deleteFile(calWavFile + ".jstk.mfcc.txt");
                            FileProcess.deleteFile(calWavFile + ".YIN.pitch.txt");

                            // start audio recording
                            Intent recordIntent = new Intent(getActivity(), AudioRecordService.class);
                            recordIntent.putExtras(mbundle);
                            getActivity().startService(recordIntent);
                        }
                    });
                    dialog.show();
                    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextSize(20);
                } else {
                    // stop audio recording
                    Intent recordIntent = new Intent(getActivity(), AudioRecordService.class);
                    getActivity().stopService(recordIntent);
                    timer_cal.stop();
                    tb_cal.setClickable(false);
                    tv_cal_content.setText("Calibrating....");
                    // start calibration
                    new Calibration().execute();
                    tb_cal.setClickable(true);
                    tv_cal_text.setText("");
                    rl_service.setVisibility(View.VISIBLE);
                    rl_test.setVisibility(View.VISIBLE);
                    timer_cal.setVisibility(View.INVISIBLE);
                }
            }
        }
    });

    tb_service.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // prevent the service button being pressed when either and test or calibration is running           
            if (tb_cal.isChecked()) {
                Toast.makeText(getActivity(), "Please turn off the calibration...", Toast.LENGTH_SHORT).show();
                tb_service.setChecked(false);
            } else if (tb_test.isChecked()) {
                Toast.makeText(getActivity(), "Please turn off the test...", Toast.LENGTH_SHORT).show();
                tb_service.setChecked(false);
            }
            // speaker counting service
            else {
                Intent countIntent = new Intent(getActivity(), SpeakerCountService.class);
                if (isChecked) {
                    getActivity().startService(countIntent);
                } else {
                    getActivity().stopService(countIntent);
                }
            }
        }
    });

    tb_test.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // prevent the test button being pressed when either and service or calibration is running           
            if (tb_cal.isChecked()) {
                Toast.makeText(getActivity(), "Please turn off the calibration...", Toast.LENGTH_SHORT).show();
                tb_test.setChecked(false);
            } else if (tb_service.isChecked()) {
                Toast.makeText(getActivity(), "Please turn off the service...", Toast.LENGTH_SHORT).show();
                tb_test.setChecked(false);
            }
            // perform the speaker counting test
            else {
                if (isChecked) {
                    // get location information
                    gps.getLocation();
                    if (gps.canGetLocation()) {
                        latitude = gps.getLatitude();
                        longitude = gps.getLongitude();
                    } else {
                        latitude = -1;
                        longitude = -1;
                    }
                    gps.stopUsingGPS();

                    timer_test.setBase(SystemClock.elapsedRealtime());
                    timer_test.start();
                    tv_debug.setText("Recording...");
                    testWavFile = testDir + "/" + FileProcess.newFileOnTime("wav");
                    // start audio recording
                    Bundle mbundle = new Bundle();
                    mbundle.putString("audiopath", testWavFile);
                    Log.i("HomeFragment", "start audio recording service");
                    Intent recordIntent = new Intent(getActivity(), AudioRecordService.class);
                    recordIntent.putExtras(mbundle);
                    date = Now.getDate();
                    start = Now.getTimeOfDay();
                    getActivity().startService(recordIntent);
                    timer_test.setVisibility(View.VISIBLE);
                } else {
                    // stop audio recording
                    Intent recordIntent = new Intent(getActivity(), AudioRecordService.class);
                    getActivity().stopService(recordIntent);
                    timer_test.stop();
                    end = Now.getTimeOfDay();
                    tb_test.setClickable(false);
                    // start speaker counting test
                    new Test().execute();
                    timer_test.setVisibility(View.INVISIBLE);
                    tb_test.setClickable(true);
                }
            }
        }
    });
    return view;
}

From source file:edu.utn.frba.grupo5303.serverenviolibre.repository.CalificacionDAODynamo.java

public CalificacionDAODynamo() {

    String regionName = "us-west-2";

    Region region = Region.getRegion(Regions.fromName(regionName));
    ClientConfiguration clientConfiguration = new ClientConfiguration().withMaxErrorRetry(20);

    ddb = new AmazonDynamoDBClient(new ProfileCredentialsProvider(), clientConfiguration);

    ddb.setRegion(region);/*w  w  w  .ja va  2 s . c  o  m*/

    mapper = new DynamoDBMapper(ddb);
}

From source file:edu.utn.frba.grupo5303.serverenviolibre.repository.FacturasDAODynamo.java

public FacturasDAODynamo() {

    String regionName = "us-west-2";

    Region region = Region.getRegion(Regions.fromName(regionName));
    ClientConfiguration clientConfiguration = new ClientConfiguration().withMaxErrorRetry(20);

    ddb = new AmazonDynamoDBClient(new ProfileCredentialsProvider(), clientConfiguration);

    ddb.setRegion(region);//  ww  w  . ja  v a 2s  .co  m

    mapper = new DynamoDBMapper(ddb);
}

From source file:edu.utn.frba.grupo5303.serverenviolibre.repository.ImagenUsuarioDAODynamo.java

public ImagenUsuarioDAODynamo() {

    String regionName = "us-west-2";

    Region region = Region.getRegion(Regions.fromName(regionName));
    ClientConfiguration clientConfiguration = new ClientConfiguration().withMaxErrorRetry(20);

    ddb = new AmazonDynamoDBClient(new ProfileCredentialsProvider(), clientConfiguration);

    ddb.setRegion(region);/*from   w  w w .j av a2s . com*/

    mapper = new DynamoDBMapper(ddb);
}

From source file:edu.utn.frba.grupo5303.serverenviolibre.services.GeoPosicionamientoPublicacionesService.java

private void setupGeoDataManager() {
    String tableName = "Posicion";
    String regionName = "us-west-2";

    Region region = Region.getRegion(Regions.fromName(regionName));
    ClientConfiguration clientConfiguration = new ClientConfiguration().withMaxErrorRetry(20);

    AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(new ProfileCredentialsProvider(), clientConfiguration);
    ddb.setRegion(region);// w  w  w  . j a  v a 2 s  .  co  m

    config = new GeoDataManagerConfiguration(ddb, tableName);
    geoDataManager = new GeoDataManager(config);
}

From source file:edu.utn.frba.grupo5303.serverenviolibre.services.GeoPosicionamientoUsuariosService.java

private void setupGeoDataManager() {
    String tableName = "PosicionUsuarios";
    String regionName = "us-west-2";

    Region region = Region.getRegion(Regions.fromName(regionName));
    ClientConfiguration clientConfiguration = new ClientConfiguration().withMaxErrorRetry(20);

    AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(new ProfileCredentialsProvider(), clientConfiguration);
    ddb.setRegion(region);// ww  w.  j  a  va  2 s . c om

    config = new GeoDataManagerConfiguration(ddb, tableName);
    geoDataManager = new GeoDataManager(config);
}

From source file:es.logongas.fpempresa.service.mail.impl.MailServiceImplAWS.java

License:Open Source License

@Override
public void send(Mail mail) {
    try {/* w w  w.j a  v  a2s. co m*/
        Session session = Session.getDefaultInstance(new Properties());

        Message message = JavaMailHelper.getMessage(mail, session);

        //Aqu es el proceso de envio
        AWSCredentials credentials = new BasicAWSCredentials(Config.getSetting("aws.accessKey"),
                Config.getSetting("aws.secretKey"));
        AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceAsyncClient(credentials);
        Region REGION = Region.getRegion(Regions.EU_WEST_1);
        client.setRegion(REGION);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        message.writeTo(outputStream);
        RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));
        SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage);
        client.sendRawEmail(rawEmailRequest);
    } catch (IllegalArgumentException | IOException | MessagingException ex) {
        throw new RuntimeException(ex);
    }
}