use of javax.annotation.Nullable in project legacy-jclouds-examples by jclouds.
the class WindowsInstanceStarter method run.
public void run() {
final String region = arguments.getRegion();
// Build a template
Template template = computeService.templateBuilder().locationId(region).imageNameMatches(arguments.getImageNamePattern()).hardwareId(arguments.getInstanceType()).build();
logger.info("Selected AMI is: %s", template.getImage().toString());
template.getOptions().inboundPorts(3389);
// Create the node
logger.info("Creating node and waiting for it to become available");
Set<? extends NodeMetadata> nodes = null;
try {
nodes = computeService.createNodesInGroup("basic-ami", 1, template);
} catch (RunNodesException e) {
logger.error(e, "Unable to start nodes; aborting");
return;
}
NodeMetadata node = Iterables.getOnlyElement(nodes);
// Wait for the administrator password
logger.info("Waiting for administrator password to become available");
// This predicate will call EC2's API to get the Windows Administrator
// password, and returns true if there is password data available.
Predicate<String> passwordReady = new Predicate<String>() {
@Override
public boolean apply(@Nullable String s) {
if (Strings.isNullOrEmpty(s))
return false;
PasswordData data = ec2Client.getWindowsServices().getPasswordDataInRegion(region, s);
if (data == null)
return false;
return !Strings.isNullOrEmpty(data.getPasswordData());
}
};
// Now wait, using RetryablePredicate
final int maxWait = 600;
final int period = 10;
final TimeUnit timeUnit = TimeUnit.SECONDS;
RetryablePredicate<String> passwordReadyRetryable = new RetryablePredicate<String>(passwordReady, maxWait, period, timeUnit);
boolean isPasswordReady = passwordReadyRetryable.apply(node.getProviderId());
if (!isPasswordReady) {
logger.error("Password is not ready after %s %s - aborting and shutting down node", maxWait, timeUnit.toString());
computeService.destroyNode(node.getId());
return;
}
// Now we can get the password data, decrypt it, and get a LoginCredentials instance
PasswordDataAndPrivateKey dataAndKey = new PasswordDataAndPrivateKey(ec2Client.getWindowsServices().getPasswordDataInRegion(region, node.getProviderId()), node.getCredentials().getPrivateKey());
WindowsLoginCredentialsFromEncryptedData f = context.getUtils().getInjector().getInstance(WindowsLoginCredentialsFromEncryptedData.class);
LoginCredentials credentials = f.apply(dataAndKey);
// Send to the log the details you need to log in to the instance with RDP
String publicIp = Iterables.getFirst(node.getPublicAddresses(), null);
logger.info("IP address: %s", publicIp);
logger.info("Login name: %s", credentials.getUser());
logger.info("Password: %s", credentials.getPassword());
// Wait for Enter on the console
logger.info("Hit Enter to shut down the node.");
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
try {
in.readLine();
} catch (IOException e) {
logger.error(e, "IOException while reading console input");
}
// Tidy up
logger.info("Shutting down");
computeService.destroyNode(node.getId());
}
use of javax.annotation.Nullable in project jsonschema2pojo by joelittlejohn.
the class IncludeJsr305AnnotationsIT method validateNullableField.
private static void validateNullableField(Field nonnullField) {
Nonnull nonnullAnnotation = nonnullField.getAnnotation(Nonnull.class);
Nullable nullableAnnotation = nonnullField.getAnnotation(Nullable.class);
assertNull("Unexpected @Nonnull annotation found.", nonnullAnnotation);
assertNotNull("Expected @Nullable annotation is missing.", nullableAnnotation);
}
use of javax.annotation.Nullable in project immutables by immutables.
the class FactoryMethodAttributesCollector method collect.
void collect() {
ExecutableElement factoryMethodElement = (ExecutableElement) protoclass.sourceElement();
Parameterizable element = (Parameterizable) (factoryMethodElement.getKind() == ElementKind.CONSTRUCTOR ? factoryMethodElement.getEnclosingElement() : type.element);
for (VariableElement parameter : factoryMethodElement.getParameters()) {
TypeMirror returnType = parameter.asType();
ValueAttribute attribute = new ValueAttribute();
attribute.isGenerateAbstract = true;
attribute.reporter = reporter;
attribute.returnType = returnType;
attribute.element = parameter;
String parameterName = parameter.getSimpleName().toString();
attribute.names = styles.forAccessorWithRaw(parameterName, parameterName);
attribute.containingType = type;
attributes.add(attribute);
}
Instantiator encodingInstantiator = protoclass.encodingInstantiator();
@Nullable InstantiationCreator instantiationCreator = encodingInstantiator.creatorFor(element);
for (ValueAttribute attribute : attributes) {
attribute.initAndValidate(instantiationCreator);
}
if (instantiationCreator != null) {
type.additionalImports(instantiationCreator.imports);
}
type.attributes.addAll(attributes);
type.throwing = extractThrowsClause(factoryMethodElement);
}
use of javax.annotation.Nullable in project immutables by immutables.
the class FromSupertypesModel method isEligibleFromType.
private boolean isEligibleFromType(TypeElement typeElement, ValueAttribute attr) {
if (!typeElement.getTypeParameters().isEmpty()) {
return false;
}
@Nullable ExecutableElement accessor = findMethod(typeElement, attr.names.get);
if (accessor == null) {
// it (null) should never happen in theory
return false;
}
boolean sameReturnType = accessor.getReturnType().toString().equals(attr.returnType.toString());
if (sameReturnType) {
return true;
}
reporter.warning("Generated 'Builder.from' method will not copy from attribute '%s'" + " because it has different return type in supertype" + " (And we cannot handle generic specialization or covarian overrides yet)." + " Sometimes it is possible to avoid this by providing abstract override method in this value object", attr.name());
return false;
}
use of javax.annotation.Nullable in project immutables by immutables.
the class ImportsTypeStringResolver method getFromSourceImports.
@Nullable
private String getFromSourceImports(String resolvable, boolean notTypeArgument) {
SourceExtraction.Imports[] importsSet = usingType == null && originType == null ? new SourceExtraction.Imports[] {} : usingType == null ? new SourceExtraction.Imports[] { originType.sourceImports() } : originType == null || usingType == originType ? new SourceExtraction.Imports[] { usingType.sourceImports() } : new SourceExtraction.Imports[] { originType.sourceImports(), usingType.sourceImports() };
for (SourceExtraction.Imports imports : importsSet) {
@Nullable String resolved = imports.classes.get(resolvable);
if (resolved != null) {
return resolved;
}
}
if (extendedClasses != null)
for (TypeElement type : extendedClasses) {
DeclaringType top = round.declaringTypeFrom(type).associatedTopLevel();
@Nullable String resolved = top.sourceImports().classes.get(resolvable);
if (resolved != null) {
return resolved;
}
}
if (implementedInterfaces != null) {
for (TypeElement type : implementedInterfaces) {
DeclaringType top = round.declaringTypeFrom(type).associatedTopLevel();
@Nullable String resolved = top.sourceImports().classes.get(resolvable);
if (resolved != null) {
return resolved;
}
}
}
// where types are present and are different
if (notTypeArgument && originType != null) {
if (!hasStarImports(importsSet)) {
// Strongly assuming it comes from originating type's package
return originType.packageOf().name() + "." + resolvable;
}
}
return null;
}
Aggregations